Revision 38415

View differences:

branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableManager.java
55 55
import org.gvsig.fmap.dal.feature.FeatureStore;
56 56
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel;
57 57
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
58
import org.gvsig.fmap.mapcontext.layers.vectorial.VectorLayer;
58 59
import org.gvsig.tools.ToolsLocator;
59 60
import org.gvsig.tools.dynobject.DynObjectManager;
60 61
import org.gvsig.tools.dynobject.DynStruct;
......
289 290
        return object instanceof TableDocument;
290 291
    }
291 292

  
292
    public TableDocument getTableDocument(FLyrVect layer) {
293
    public TableDocument getTableDocument(VectorLayer layer) {
293 294
        if (layer == null) {
294 295
            return null;
295 296
        }
......
303 304
        return null;
304 305
    }
305 306

  
306
    public void removeTableDocument(FLyrVect layer) {
307
    public void removeTableDocument(VectorLayer layer) {
307 308
        TableDocument doc = getTableDocument(layer);
308 309
        // Only remove it if it exists
309 310
        if (doc != null) {
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/gui/FeatureTableDocumentPanel.java
26 26
 */
27 27
package org.gvsig.app.project.documents.table.gui;
28 28

  
29
import java.lang.reflect.InvocationTargetException;
30

  
31
import javax.swing.SwingUtilities;
32

  
29 33
import org.slf4j.Logger;
30 34
import org.slf4j.LoggerFactory;
31 35

  
......
131 135
            try {
132 136
                if (selectionIsEmpty != getFeatureSelection().isEmpty()) {
133 137
                    selectionIsEmpty = !selectionIsEmpty;
134
                    PluginServices.getMainFrame().enableControls();
138
        			enableControls(notification);
135 139
                }
136 140
            } catch (DataException e) {
137 141
                LOG.error("Error getting the current selection", e);
138 142
            }
139
        } else
140
            if (notification instanceof ColumnHeaderSelectionChangeNotification) {
141
                PluginServices.getMainFrame().enableControls();
142
            }
143
		} else if (notification instanceof ColumnHeaderSelectionChangeNotification) {
144
			enableControls(notification);
145
		}
143 146
    }
144 147

  
148
	private void enableControls(Object notification) {
149
		try {
150
			SwingUtilities.invokeLater(new Runnable() {
151
				public void run() {
152
					PluginServices.getMainFrame().enableControls();
153
				}
154
			});
155
		} catch (Exception e) {
156
			LOG.warn("Error calling enableControls() after notification: "
157
					+ notification, e);
158
		}
159
	}
160

  
145 161
    private void initialize() throws DataException {
146 162
        getTablePanel().getTable().addObserver(this);
147 163
        getFeatureSelection().addObserver(this);
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableDocument.java
49 49
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
50 50
import org.gvsig.fmap.dal.feature.FeatureType;
51 51
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
52
import org.gvsig.fmap.mapcontext.layers.vectorial.VectorLayer;
52 53
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureStoreModel;
53 54
import org.gvsig.tools.dispose.DisposableIterator;
54 55
import org.gvsig.tools.evaluator.Evaluator;
......
77 78

  
78 79
    private List<TableLink> linkTable;
79 80

  
80
    private FLyrVect associatedLayer;
81
    private VectorLayer associatedLayer;
81 82

  
82 83
    private FeatureQuery query;
83 84

  
......
303 304
        }
304 305
    }
305 306

  
306
    public FLyrVect getAssociatedLayer() {
307
    public VectorLayer getAssociatedLayer() {
307 308
        return associatedLayer;
308 309
    }
309 310

  
310
    public void setAssociatedLayer(FLyrVect associatedLayer) {
311
    public void setAssociatedLayer(VectorLayer associatedLayer) {
311 312
        this.associatedLayer = associatedLayer;
312 313
    }
313 314

  
branches/v2_0_0_prep/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/ShowGraphicsLayerTable.java
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.app.extension;
23

  
24
import java.beans.PropertyChangeEvent;
25
import java.beans.PropertyChangeListener;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.ApplicationManager;
31
import org.gvsig.app.project.ProjectManager;
32
import org.gvsig.app.project.documents.table.TableDocument;
33
import org.gvsig.app.project.documents.table.TableManager;
34
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
35
import org.gvsig.app.project.documents.view.ViewDocument;
36
import org.gvsig.app.project.documents.view.ViewManager;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.mapcontext.layers.CancelationException;
40
import org.gvsig.fmap.mapcontext.layers.FLayer;
41
import org.gvsig.fmap.mapcontext.layers.FLayers;
42
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
43
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
44
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
45
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer;
46
import org.gvsig.fmap.mapcontext.layers.vectorial.VectorLayer;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

  
50
/**
51
 * Opens a table document of the current view's graphic layer.
52
 * 
53
 * @author gvSIG team
54
 */
55
public class ShowGraphicsLayerTable extends Extension implements
56
		PropertyChangeListener {
57

  
58
	private static final Logger LOG = LoggerFactory
59
			.getLogger(ShowGraphicsLayerTable.class);
60

  
61
	private ApplicationManager appManager = ApplicationLocator.getManager();
62

  
63
	/**
64
	 * @see org.gvsig.andami.plugins.IExtension#isEnabled()
65
	 */
66
	public boolean isEnabled() {
67
		return getCurrentViewDocument() != null;
68
	}
69

  
70
	private ViewDocument getCurrentViewDocument() {
71
		return (ViewDocument) appManager
72
				.getActiveDocument(ViewManager.TYPENAME);
73
	}
74

  
75
	/**
76
	 * @see org.gvsig.andami.plugins.IExtension#isVisible()
77
	 */
78
	public boolean isVisible() {
79
		try {
80
			ViewDocument document = getCurrentViewDocument();
81
			if (document == null) {
82
				return false;
83
			}
84
			GraphicLayer graphicsLayer = document.getMapContext()
85
					.getGraphicsLayer();
86
			TableManager tableManager = getTableManager();
87
			TableDocument tableDocument = tableManager
88
					.getTableDocument(graphicsLayer);
89
			return tableDocument != null
90
					|| document.getMapContext().getGraphicsLayer()
91
							.getFeatureStore().getFeatureCount() > 0;
92
		} catch (DataException e) {
93
			LOG.error("Error checking if the current document is a "
94
					+ "view and has data in the graphics layer", e);
95
			return false;
96
		}
97
	}
98

  
99
	/**
100
	 * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
101
	 */
102
	public void execute(String action) {
103

  
104
		ViewDocument document = getCurrentViewDocument();
105
		GraphicLayer graphicsLayer = document.getMapContext()
106
				.getGraphicsLayer();
107

  
108
		ProjectManager projectManager = getProjectManager();
109
		TableManager tableManager = getTableManager();
110

  
111
		TableDocument tableDocument = tableManager
112
				.getTableDocument(graphicsLayer);
113
		FeatureStore fs = graphicsLayer.getFeatureStore();
114

  
115
		if (tableDocument == null) {
116
			tableDocument = (TableDocument) projectManager.createDocument(
117
					TableManager.TYPENAME,
118
					PluginServices.getText(this, "Tabla_de_Atributos") + ": "
119
							+ graphicsLayer.getName());
120
			tableDocument.setStore(fs);
121
			tableDocument.setAssociatedLayer(graphicsLayer);
122
			projectManager.getCurrentProject().add(tableDocument);
123
		}
124

  
125
		tableDocument.setModified(true);
126
		FeatureTableDocumentPanel featureTableDocumentPanel = (FeatureTableDocumentPanel) tableManager
127
				.getMainWindow(tableDocument);
128

  
129
		appManager.getUIManager().addWindow(featureTableDocumentPanel);
130

  
131
	}
132

  
133
	private ProjectManager getProjectManager() {
134
		return ProjectManager.getInstance();
135
	}
136

  
137
	private TableManager getTableManager() {
138
		TableManager tableManager = (TableManager) getProjectManager()
139
				.getDocumentManager(TableManager.TYPENAME);
140
		return tableManager;
141
	}
142

  
143
	/**
144
	 * @see org.gvsig.andami.plugins.IExtension#initialize()
145
	 */
146
	public void initialize() {
147
		registerIcons();
148
	}
149

  
150
	public void postInitialize() {
151
		// Listen just in case a view document is removed, to remove also
152
		// the related graphics layer table document, if any
153
		getProjectManager().getCurrentProject().addPropertyChangeListener(this);
154
	}
155

  
156
	private void registerIcons() {
157
		PluginServices.getIconTheme().registerDefault(
158
				"layer-show-attribute-table",
159
				this.getClass().getClassLoader()
160
						.getResource("images/ResultConsulta.png"));
161
	}
162

  
163
	public void propertyChange(PropertyChangeEvent evt) {
164
		if ("delDocument".equals(evt.getPropertyName())) {
165
			if (evt.getOldValue() != null
166
					&& evt.getOldValue() instanceof ViewDocument) {
167
				ViewDocument viewDocument = (ViewDocument) evt.getOldValue();
168
				getTableManager().removeTableDocument(
169
						viewDocument.getMapContext().getGraphicsLayer());
170
			}
171
		}
172
	}
173
}

Also available in: Unified diff