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