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 / dispose / DisposableManagementExtension.java @ 40558
History | View | Annotate | Download (3.46 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2009 {} {{Task}}
|
27 |
*/
|
28 |
package org.gvsig.app.extension.dispose; |
29 |
|
30 |
import java.util.Iterator; |
31 |
import java.util.Set; |
32 |
|
33 |
import javax.swing.JOptionPane; |
34 |
|
35 |
import org.gvsig.andami.plugins.Extension; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.dispose.Disposable; |
38 |
import org.gvsig.tools.dispose.DisposableInfo; |
39 |
import org.gvsig.tools.dispose.DisposableManager; |
40 |
import org.gvsig.tools.exception.BaseException; |
41 |
import org.slf4j.Logger; |
42 |
import org.slf4j.LoggerFactory; |
43 |
|
44 |
/**
|
45 |
* An extension to view and manage {@link Disposable} objects which are still
|
46 |
* bound.
|
47 |
*
|
48 |
* TODO: remove this extension and replace with a better one, maybe based on
|
49 |
* scripting.
|
50 |
*
|
51 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
52 |
*/
|
53 |
public class DisposableManagementExtension extends Extension { |
54 |
|
55 |
public static String SHOW_COMMAND = "tools-devel-disposables-show-pendings"; |
56 |
public static String DISPOSE_ALL_COMMAND = "tools-devel-disposables-free-all"; |
57 |
|
58 |
private static final Logger LOG = |
59 |
LoggerFactory.getLogger(DisposableManagementExtension.class); |
60 |
|
61 |
private DisposableManager manager;
|
62 |
|
63 |
public void initialize() { |
64 |
// Nothing to do
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void postInitialize() { |
69 |
super.postInitialize();
|
70 |
manager = ToolsLocator.getDisposableManager(); |
71 |
} |
72 |
|
73 |
public void execute(String actionCommand) { |
74 |
|
75 |
if (DISPOSE_ALL_COMMAND.equals(actionCommand)) {
|
76 |
disposeAll(); |
77 |
} else {
|
78 |
if (SHOW_COMMAND.equals(actionCommand)) {
|
79 |
showDisposables(); |
80 |
} |
81 |
} |
82 |
} |
83 |
|
84 |
@SuppressWarnings("unchecked") |
85 |
private void showDisposables() { |
86 |
Set<DisposableInfo> disposables =
|
87 |
(Set<DisposableInfo>) manager.getBoundDisposables();
|
88 |
|
89 |
String message;
|
90 |
if (disposables.size() < 1) { |
91 |
message = "There aren't any bound Disposables actually";
|
92 |
} else {
|
93 |
LOG.info("Disposable infos with stack trace:");
|
94 |
StringBuffer buffer = new StringBuffer(); |
95 |
int i = 1; |
96 |
for (Iterator<DisposableInfo> iterator = disposables.iterator(); iterator.hasNext();) { |
97 |
DisposableInfo disposableInfo = iterator.next(); |
98 |
buffer.append(i++).append(": ").append(
|
99 |
disposableInfo.getDisposable()).append('\n');
|
100 |
LOG.info("\n" + disposableInfo.toString());
|
101 |
} |
102 |
message = buffer.toString(); |
103 |
} |
104 |
JOptionPane.showMessageDialog(null, message); |
105 |
} |
106 |
|
107 |
private void disposeAll() { |
108 |
try {
|
109 |
manager.releaseAll(); |
110 |
} catch (BaseException ex) {
|
111 |
LOG.error("Error disposing all bound disposable objects", ex);
|
112 |
} |
113 |
} |
114 |
|
115 |
public boolean isEnabled() { |
116 |
return true; |
117 |
} |
118 |
|
119 |
public boolean isVisible() { |
120 |
return true; |
121 |
} |
122 |
} |