svn-gvsig-desktop / 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 @ 42811
History | View | Annotate | Download (3.71 KB)
1 | 42557 | dmartinezizquierdo | /*
|
---|---|---|---|
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 | } |