01: package com.vividsolutions.jump.workbench.ui;
02:
03: import com.vividsolutions.jump.workbench.WorkbenchContext;
04: import com.vividsolutions.jump.workbench.model.*;
05: import com.vividsolutions.jump.workbench.model.FeatureEvent;
06: import com.vividsolutions.jump.workbench.model.Layer;
07: import com.vividsolutions.jump.workbench.model.LayerListener;
08: import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
09:
10: /**
11: * Displays and stays in sync with a single Layer.
12: */
13: public class OneLayerAttributeTab extends AttributeTab {
14: public OneLayerAttributeTab(WorkbenchContext context,
15: TaskFrame taskFrame, LayerManagerProxy layerManagerProxy) {
16: super (new InfoModel(), context, taskFrame, layerManagerProxy,
17: true);
18: context.getLayerManager().addLayerListener(new LayerListener() {
19: public void featuresChanged(FeatureEvent e) {
20: if (getLayerTableModel() == null) {
21: //Get here after attribute viewer window is closed [Jon Aquino]
22: return;
23: }
24: if ((e.getLayer() == getLayerTableModel().getLayer())
25: && (e.getType() == FeatureEventType.ADDED)) {
26: //DELETED events are already handled in LayerTableModel
27: getLayerTableModel().addAll(e.getFeatures());
28: }
29: }
30:
31: public void layerChanged(LayerEvent e) {
32: }
33:
34: public void categoryChanged(CategoryEvent e) {
35: }
36: });
37: }
38:
39: public OneLayerAttributeTab setLayer(Layer layer) {
40: if (!getModel().getLayers().isEmpty()) {
41: getModel().remove(getLayer());
42: }
43:
44: //InfoModel#add must be called after the AttributeTab is created; otherwise
45: //layer won't be added to the Attribute Tab -- the AttributeTab listens for
46: //the event fired by InfoModel#add. [Jon Aquino]
47: getModel().add(layer,
48: layer.getFeatureCollectionWrapper().getFeatures());
49:
50: return this ;
51: }
52:
53: public Layer getLayer() {
54: //null LayerTableModel if for example the user has just removed the layer
55: //from the LayerManager [Jon Aquino]
56: return (getLayerTableModel() != null) ? getLayerTableModel()
57: .getLayer() : null;
58: }
59:
60: public LayerTableModel getLayerTableModel() {
61: return (!getModel().getLayerTableModels().isEmpty()) ? (LayerTableModel) getModel()
62: .getLayerTableModels().iterator().next()
63: : null;
64: }
65: }
|