Revision 42557

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1255 1255
_Translations_package=Paquetes de traducci\u00f3n
1256 1256

  
1257 1257
document_not_available=Documento no disponible
1258
symbol_level=Nivel %(level)
1258
symbol_level=Nivel %(level)
1259

  
1260
_Selected_features=Elementos Totales/Elementos Seleccionados
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1174 1174
Show_pendings=Show pendings
1175 1175
_Translations_package=Translation packages
1176 1176
document_not_available=Document not available
1177
symbol_level=Level %(level)
1177
symbol_level=Level %(level)
1178

  
1179
_Selected_features=Total Features/Selected Features
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml
58 58
      priority="1">
59 59
    </extension>
60 60

  
61
    <extension class-name="org.gvsig.app.extension.selectioncount.SelectionCountExtension"
62
      description="Counts selected features"
63
      active="true">
64
    </extension>
65

  
61 66
    <extension class-name="org.gvsig.app.extension.CheckSOAndArquitectureExtension"
62 67
      description="Check OS and architecture of installed packages"
63 68
      active="true"
......
1217 1222
            />
1218 1223

  
1219 1224
        </extension>
1220
        
1225

  
1221 1226
        <extension
1222 1227
          class-name="org.gvsig.app.extension.CreateDefaultFormDefinitionExtension"
1223 1228
          description="" active="true" priority="1">
1224 1229

  
1225
          <action 
1230
          <action
1226 1231
            name="layer-create-default-form-definition"
1227
            label="Create default form definition" 
1228
            tooltip="Create default form definition" 
1232
            label="Create default form definition"
1233
            tooltip="Create default form definition"
1229 1234
            position="601400000"
1230
            action-command="layer-create-default-form-definition" 
1235
            action-command="layer-create-default-form-definition"
1231 1236
            icon="layer-create-default-form-definition"
1232
            accelerator="" 
1237
            accelerator=""
1233 1238
          />
1234 1239

  
1235
          <menu 
1236
              name="layer-create-default-form-definition" 
1237
              text="Layer/Create default form (experimental)" 
1240
          <menu
1241
              name="layer-create-default-form-definition"
1242
              text="Layer/Create default form (experimental)"
1238 1243
          />
1239 1244

  
1240
        </extension>        
1245
        </extension>
1241 1246

  
1242 1247
  </extensions>
1243 1248

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/selectioncount/SelectionCountExtension.java
1
/*
2
 * Copyright 2015 DiSiD Technologies S.L.L. All rights reserved.
3
 *
4
 * Project  : DiSiD org.gvsig.app.mainplugin
5
 * SVN Id   : $Id$
6
 */
7
package org.gvsig.app.extension.selectioncount;
8

  
9
import javax.swing.border.BevelBorder;
10

  
11
import org.gvsig.andami.PluginServices;
12
import org.gvsig.andami.PluginsLocator;
13
import org.gvsig.andami.plugins.Extension;
14
import org.gvsig.andami.ui.mdiFrame.MainFrame;
15
import org.gvsig.andami.ui.mdiManager.IWindow;
16
import org.gvsig.app.ApplicationLocator;
17
import org.gvsig.app.ApplicationManager;
18
import org.gvsig.app.project.documents.view.ViewDocument;
19
import org.gvsig.app.project.documents.view.gui.IView;
20
import org.gvsig.fmap.mapcontext.layers.FLayer;
21
import org.gvsig.fmap.mapcontext.layers.FLayers;
22
import org.gvsig.fmap.mapcontrol.MapControl;
23
import org.gvsig.fmap.mapcontrol.MapControlCreationListener;
24
import org.gvsig.fmap.mapcontrol.MapControlLocator;
25
import org.gvsig.gui.beans.controls.IControl;
26
import org.gvsig.gui.beans.controls.label.Label;
27

  
28
/**
29
 * Controls the extension Selection count, which shows the selected features in the status bar
30
 * @author Daniel Martinez
31
 *
32
 */
33
public class SelectionCountExtension extends Extension {
34
    private IControl control;
35
    private SelectionCount selectionCount=null;
36

  
37
    @Override
38
    public void initialize() {
39
        // Do nothing
40

  
41
    }
42

  
43
    @Override
44
    public void execute(String actionCommand) {
45
     // Do nothing
46

  
47
    }
48

  
49
    @Override
50
    public boolean isEnabled() {
51
        //FIXME This should been done through a window listener to be triggered when it changes to another one.
52
        if (this.control==null){
53
            this.control=createLabel();
54
        }
55
        if (selectionCount==null){
56
            selectionCount=new SelectionCount(control);
57
        }
58

  
59
        IView view = getActiveView();
60
        if (view != null) {
61
            selectionCount.showFeatureCount(view.getMapControl());
62
        }
63

  
64
        return true;
65
    }
66

  
67
    @Override
68
    public boolean isVisible() {
69
        IWindow window = getActiveWindow();
70
        if (window instanceof IView) {
71
            IView view = (IView)window;
72
            ViewDocument viewDocument = view.getViewDocument();
73
            FLayers layers = viewDocument.getMapContext().getLayers();
74
            if (layers!=null){
75
                FLayer[] activeLayers = layers.getActives();
76
                if (activeLayers!=null && activeLayers.length>0){
77
                    return true;
78
                }
79
            }
80
        }
81

  
82
        return false;
83
    }
84

  
85
    private IView getActiveView() {
86
        ApplicationManager application = ApplicationLocator.getManager();
87
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
88
        return view;
89
    }
90

  
91
    private IWindow getActiveWindow() {
92
        ApplicationManager application = ApplicationLocator.getManager();
93
        return application.getActiveWindow();
94
    }
95

  
96
    @Override
97
    public void postInitialize() {
98
        if (this.control==null){
99
            this.control=createLabel();
100
        }
101
        MapControlLocator.getMapControlManager().addMapControlCreationListener(new MapControlCreationListener() {
102

  
103
            @Override
104
            public MapControl mapControlCreated(MapControl mapControl) {
105
                new SelectionCount(mapControl,control);
106
                return mapControl;
107
            }
108
        });
109
    }
110

  
111
    private IControl createLabel(){
112
        MainFrame mainFrame = PluginsLocator.getMainFrame();
113
        Label label=new Label();
114
        label.setName("selectionCount");
115
        String tooltip=PluginServices.getText(this,"_Selected_features");
116
        label.setToolTipText(tooltip);
117
        label.setBorder(new BevelBorder(BevelBorder.LOWERED));
118
        mainFrame.addStatusBarControl(this.getClass(), label);
119
        return label;
120
    }
121
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/selectioncount/SelectionCount.java
1
/*
2
 * Copyright 2015 DiSiD Technologies S.L.L. All rights reserved.
3
 *
4
 * Project  : DiSiD org.gvsig.app.mainplugin
5
 * SVN Id   : $Id$
6
 */
7
package org.gvsig.app.extension.selectioncount;
8

  
9
import javax.swing.JLabel;
10

  
11
import org.gvsig.fmap.dal.exception.DataException;
12
import org.gvsig.fmap.dal.feature.FeatureSelection;
13
import org.gvsig.fmap.dal.feature.FeatureStore;
14
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
15
import org.gvsig.fmap.mapcontext.events.AtomicEvent;
16
import org.gvsig.fmap.mapcontext.events.listeners.AtomicEventListener;
17
import org.gvsig.fmap.mapcontext.layers.FLayer;
18
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
19
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
20
import org.gvsig.fmap.mapcontext.layers.LayerListener;
21
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
22
import org.gvsig.fmap.mapcontrol.MapControl;
23
import org.gvsig.gui.beans.controls.IControl;
24
import org.gvsig.tools.observer.Observable;
25
import org.gvsig.tools.observer.Observer;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
/**
30
 * Counts total and selected features and shows them in the status bar
31
 * @author Daniel Martinez
32
 *
33
 */
34
public class SelectionCount implements AtomicEventListener, LayerListener,Observer{
35
    private static Logger logger =
36
        LoggerFactory.getLogger(SelectionCount.class);
37

  
38
    private MapControl mapControl;
39
    private IControl control;
40

  
41
    /**
42
     * Listens the map control to show the count through the control in the status bar
43
     * @param mapControl
44
     * @param control
45
     */
46
    public SelectionCount (MapControl mapControl, IControl control){
47
        this.mapControl=mapControl;
48
        this.control=control;
49
        mapControl.getMapContext().addAtomicEventListener(this);
50
    }
51

  
52
    /**
53
     * To use methods showFeatureCount and clean with another map control
54
     * @param control
55
     */
56
    public SelectionCount (IControl control){
57
        this.control=control;
58
    }
59

  
60
    @Override
61
    public void atomicEvent(AtomicEvent e) {
62
        LayerCollectionEvent[] events = e.getLayerCollectionEvents();
63
        for( int i=0; i<events.length ; i++ ) {
64
            if( events[i].getEventType() == LayerCollectionEvent.LAYER_ADDED ) {
65
                FLayer fLayer = events[i].getAffectedLayer();
66
                fLayer.addLayerListener(this);
67
            }
68
            if( events[i].getEventType() == LayerCollectionEvent.LAYER_REMOVED ) {
69
                FLayer fLayer = events[i].getAffectedLayer();
70
                fLayer.removeLayerListener(this);
71
                showFeatureCount(mapControl);
72
            }
73
        }
74
    }
75

  
76
    @Override
77
    public void visibilityChanged(LayerEvent e) {
78
        // Do nothing
79
    }
80

  
81
    @Override
82
    public void activationChanged(LayerEvent e) {
83
        if (e.getEventType()==LayerEvent.ACTIVATION_CHANGED){
84
            showFeatureCount(mapControl);
85
            FLayer fLayer =e.getSource();
86
            if (fLayer.isActive()){
87
                if (fLayer instanceof FLyrVect) {
88
                    FLyrVect lyrVect = (FLyrVect) fLayer;
89
                    lyrVect.getFeatureStore().addObserver(this);
90
                }
91
            }else{
92
                if (fLayer instanceof FLyrVect) {
93
                    FLyrVect lyrVect = (FLyrVect) fLayer;
94
                    lyrVect.getFeatureStore().deleteObserver(this);
95
                }
96
            }
97
        }
98
    }
99

  
100
    @Override
101
    public void nameChanged(LayerEvent e) {
102
     // Do nothing
103
    }
104

  
105
    @Override
106
    public void editionChanged(LayerEvent e) {
107
     // Do nothing
108
    }
109

  
110
    @Override
111
    public void drawValueChanged(LayerEvent e) {
112
     // Do nothing
113
    }
114

  
115
    @Override
116
    public void update(final Observable observable, final Object notification) {
117
        if (notification instanceof FeatureStoreNotification) {
118
            FeatureStoreNotification event
119
                    = (FeatureStoreNotification) notification;
120
            if (event.getType() == FeatureStoreNotification.AFTER_DELETE ||
121
                event.getType() == FeatureStoreNotification.AFTER_INSERT ||
122
                event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING ||
123
                event.getType() == FeatureStoreNotification.SELECTION_CHANGE ){
124

  
125
                if (event.getSource() instanceof FeatureStore){
126
                    showFeatureCount(mapControl);
127
                }
128
            }
129
        }
130
    }
131

  
132
    /**
133
     * Gets the features from the selected layers and shows them through the control
134
     * @param mapControl
135
     */
136
    public void showFeatureCount(MapControl mapControl){
137
        Long totalFeaturesCount=Long.valueOf(0);
138
        Long selectedFeaturesCount=Long.valueOf(0);;
139
        if (mapControl!=null){
140
            FLayer[] actives =mapControl.getMapContext().getLayers().getActives();
141
            if (actives!=null && actives.length>0){
142
                for(FLayer fLayer:actives){
143
                    if (fLayer instanceof FLyrVect) {
144
                        FLyrVect lyrVect = (FLyrVect) fLayer;
145
                        FeatureStore featureStore=lyrVect.getFeatureStore();
146
                        if (featureStore != null) {
147
                            try {
148
                                totalFeaturesCount +=
149
                                    featureStore.getFeatureCount();
150
                            } catch (DataException e) {
151
                                logger.warn(
152
                                    "Problem obtaining total features count");
153
                                totalFeaturesCount = 0L;
154
                            }
155
                            try {
156
                                FeatureSelection featureSelection =
157
                                    featureStore.getFeatureSelection();
158
                                if (featureSelection != null) {
159
                                    selectedFeaturesCount +=
160
                                        featureSelection.getSize();
161
                                }
162
                            } catch (DataException e) {
163
                                logger.warn(
164
                                    "Problem obtaining selected features count");
165
                                selectedFeaturesCount = 0L;
166
                            }
167
                        }
168
                    }
169
                }
170
                messageToStatusBar(totalFeaturesCount,selectedFeaturesCount);
171
            }else {
172
                clean();
173
            }
174
        }else {
175
            clean();
176
        }
177
    }
178

  
179
    /**
180
     * Cleans the text shown in the control
181
     */
182
    public void clean(){
183
        if (control!=null && control instanceof JLabel ){
184
            JLabel jlabel = (JLabel)control;
185
            jlabel.setText("");
186
        }
187
    }
188

  
189
    private void messageToStatusBar(Long totalFeaturesCount, Long selectedFeaturesCount){
190
        String strTotal;
191
        String strSelected;
192
        if (totalFeaturesCount!=null){
193
            strTotal=totalFeaturesCount.toString();
194
        }else{
195
            strTotal="N/A";
196
        }
197
        if (selectedFeaturesCount!=null){
198
            strSelected=selectedFeaturesCount.toString();
199
        }else{
200
            strSelected="N/A";
201
        }
202
        if (control!=null && control instanceof JLabel ){
203
            JLabel jlabel = (JLabel)control;
204
            jlabel.setText(strSelected+"/"+strTotal);
205
        }
206
    }
207

  
208
}

Also available in: Unified diff