Revision 44455
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.ui/src/main/java/org/gvsig/gui/beans/swing/JComboBoxFonts.java | ||
---|---|---|
30 | 30 |
/** |
31 | 31 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
32 | 32 |
*/ |
33 |
public class JComboBoxFonts extends JComboBox{ |
|
34 |
private static final long serialVersionUID = -1096327332248927959L; |
|
33 |
public class JComboBoxFonts extends JComboBox { |
|
35 | 34 |
|
36 |
public JComboBoxFonts() { |
|
37 |
super(); |
|
38 |
initialize(); |
|
39 |
} |
|
35 |
private static final long serialVersionUID = -1096327332248927959L; |
|
40 | 36 |
|
41 |
private void initialize() { |
|
42 |
// Font info is obtained from the current graphics environment. |
|
43 |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
37 |
public JComboBoxFonts() { |
|
38 |
super(); |
|
39 |
initialize(); |
|
40 |
} |
|
44 | 41 |
|
45 |
// --- Get an array of font names (smaller than the number of fonts) |
|
46 |
String[] fontNames = ge.getAvailableFontFamilyNames(); |
|
47 |
for (int i = 0; i < fontNames.length; i++) { |
|
48 |
addItem(fontNames[i]); |
|
49 |
}; |
|
50 |
} |
|
42 |
private void initialize() { |
|
43 |
// Font info is obtained from the current graphics environment. |
|
44 |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
51 | 45 |
|
46 |
// --- Get an array of font names (smaller than the number of fonts) |
|
47 |
String[] fontNames = ge.getAvailableFontFamilyNames(); |
|
48 |
for (int i = 0; i < fontNames.length; i++) { |
|
49 |
addItem(fontNames[i]); |
|
50 |
}; |
|
51 |
try { |
|
52 |
this.setSelectedItem("Arial"); |
|
53 |
this.setSelectedItem("DejaVu Sans"); |
|
54 |
this.setSelectedItem("Liberation Sans"); |
|
55 |
this.setSelectedItem("Serif"); |
|
56 |
|
|
57 |
} catch (Exception ex) { |
|
58 |
|
|
59 |
} |
|
60 |
} |
|
61 |
|
|
52 | 62 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/dynamiclegend/DefaultDynamicVectorLegend.java | ||
---|---|---|
208 | 208 |
//TODO: Optimizar por obtener solo los campos que usan las expresiones |
209 | 209 |
FeatureStore featureStore) throws DataException { |
210 | 210 |
if (requiredAttributes == null) { |
211 |
requiredAttributes = new String[]{}; |
|
211 |
int arraySize = featureStore.getDefaultFeatureType().size(); |
|
212 |
requiredAttributes = new String[arraySize]; |
|
212 | 213 |
for (int i = 0; i < featureStore.getDefaultFeatureType().size(); i++) { |
213 | 214 |
FeatureAttributeDescriptor att = featureStore.getDefaultFeatureType().get(i); |
214 | 215 |
requiredAttributes[i] = att.getName(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContextLibrary.java | ||
---|---|---|
42 | 42 |
import org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory; |
43 | 43 |
import org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory; |
44 | 44 |
import org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory; |
45 |
import org.gvsig.tools.ToolsLocator; |
|
46 | 45 |
import org.gvsig.tools.library.AbstractLibrary; |
47 | 46 |
import org.gvsig.tools.library.LibraryException; |
48 | 47 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
49 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
50 | 48 |
import org.gvsig.tools.util.Caller; |
51 | 49 |
import org.gvsig.tools.util.impl.DefaultCaller; |
52 | 50 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/ExtendedPropertiesHelper.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.util.HashMap; |
27 | 27 |
import java.util.Map; |
28 |
import java.util.Map.Entry; |
|
29 |
import java.util.Set; |
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.dynobject.DynStruct; |
|
30 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
30 | 31 |
|
31 | 32 |
import org.slf4j.Logger; |
32 | 33 |
import org.slf4j.LoggerFactory; |
33 | 34 |
|
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.dynobject.DynStruct; |
|
36 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
37 | 35 |
import org.gvsig.tools.persistence.Persistent; |
38 |
import org.gvsig.tools.persistence.PersistentState; |
|
39 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
40 | 36 |
import org.gvsig.tools.util.Callable; |
37 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
|
41 | 38 |
|
42 |
public class ExtendedPropertiesHelper implements ExtendedPropertiesSupport, Persistent { |
|
39 |
public class ExtendedPropertiesHelper extends PropertiesSupportHelper implements ExtendedPropertiesSupport, Persistent {
|
|
43 | 40 |
|
44 | 41 |
private static final Logger logger = LoggerFactory.getLogger(ExtendedPropertiesHelper.class); |
45 | 42 |
|
... | ... | |
75 | 72 |
|
76 | 73 |
state.set("propertiesHelper",propertiesHelper); |
77 | 74 |
|
78 |
*/ |
|
79 |
private Map properties = new HashMap(); |
|
80 |
|
|
81 |
@Override |
|
75 |
*/ |
|
76 |
@Override |
|
82 | 77 |
public Object getProperty(Object key) { |
83 |
return properties.get(key);
|
|
78 |
return this.getProperty((String) key);
|
|
84 | 79 |
} |
85 | 80 |
|
86 |
@Override
|
|
81 |
@Override
|
|
87 | 82 |
public void setProperty(Object key, Object val) { |
88 |
properties.put(key, val);
|
|
83 |
this.setProperty((String) key, val);
|
|
89 | 84 |
} |
90 | 85 |
|
91 |
@Override
|
|
86 |
@Override
|
|
92 | 87 |
public Map getExtendedProperties() { |
93 |
return properties;
|
|
88 |
return this.getProperties();
|
|
94 | 89 |
} |
95 | 90 |
|
96 | 91 |
public void setExtendedProperties(Map properties) { |
97 |
this.properties = new HashMap(); |
|
98 |
if( properties!=null ) { |
|
99 |
// this.properties.putAll(properties); |
|
100 |
this.copyFrom(properties); |
|
101 |
} |
|
92 |
this.setProperties(properties); |
|
102 | 93 |
} |
103 | 94 |
|
104 |
private void copyFrom(Map properties) { |
|
105 |
for(Entry entry : (Set<Entry>)properties.entrySet() ) { |
|
106 |
Object key = entry.getKey(); |
|
107 |
if( key == null ) { |
|
108 |
continue; |
|
109 |
} |
|
110 |
Object value; |
|
111 |
try { |
|
112 |
value = entry.getValue(); |
|
113 |
} catch(Throwable th) { |
|
114 |
if( logger.isDebugEnabled() ) { |
|
115 |
logger.warn("Can't get property "+key.toString()+".",th); |
|
116 |
} else { |
|
117 |
logger.warn("Can't get property "+key.toString()+"."); |
|
118 |
} |
|
119 |
value = null; |
|
120 |
} |
|
121 |
this.properties.put(key, value); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
127 |
state.set("properties", properties); |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
132 |
this.properties = new HashMap(); |
|
133 |
Map props = (Map) state.get("properties"); |
|
134 |
if( props != null) { |
|
135 |
copyFrom(props); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 | 95 |
public static class RegisterPersistence implements Callable { |
140 | 96 |
|
141 |
@Override
|
|
97 |
@Override
|
|
142 | 98 |
public Object call() { |
143 | 99 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
144 | 100 |
DynStruct definition = manager.addDefinition( |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/AutomaticDetectionOfTypes.java | ||
---|---|---|
16 | 16 |
public class AutomaticDetectionOfTypes { |
17 | 17 |
|
18 | 18 |
public interface Rows { |
19 |
|
|
19 | 20 |
public List<String> nextRowValues(); |
20 | 21 |
} |
21 |
|
|
22 |
|
|
22 | 23 |
private static class PossibleDataType { |
23 | 24 |
|
24 | 25 |
public boolean possibleInt = true; |
... | ... | |
43 | 44 |
private String getFullFileName() { |
44 | 45 |
return this.filename; |
45 | 46 |
} |
46 |
|
|
47 |
|
|
47 | 48 |
@SuppressWarnings({"UseSpecificCatch", "ResultOfObjectAllocationIgnored"}) |
48 | 49 |
public int[] detect(int columns, Rows rows, boolean isFirstLineHeader, Locale locale) throws IOException { |
49 | 50 |
List<PossibleDataType> possibleDataTypes; |
... | ... | |
210 | 211 |
return false; |
211 | 212 |
} |
212 | 213 |
} |
213 |
|
|
214 |
|
|
214 | 215 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/DefaultViewDocument.java | ||
---|---|---|
21 | 21 |
* For any additional information, do not hesitate to contact us |
22 | 22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
23 | 23 |
*/ |
24 |
|
|
25 | 24 |
package org.gvsig.app.project.documents.view; |
26 | 25 |
|
27 | 26 |
import javax.swing.JOptionPane; |
... | ... | |
50 | 49 |
import org.slf4j.Logger; |
51 | 50 |
import org.slf4j.LoggerFactory; |
52 | 51 |
|
53 |
|
|
54 |
|
|
55 | 52 |
/** |
56 | 53 |
* Clase que representa una vista del proyecto |
57 |
*
|
|
54 |
* |
|
58 | 55 |
*/ |
59 |
|
|
60 | 56 |
public class DefaultViewDocument extends BaseViewDocument { |
61 | 57 |
|
62 |
private static Logger logger = LoggerFactory.getLogger(DefaultViewDocument.class);
|
|
63 |
/**
|
|
64 |
*
|
|
65 |
*/
|
|
66 |
private static final long serialVersionUID = 676711512482334764L;
|
|
58 |
private static Logger logger = LoggerFactory.getLogger(DefaultViewDocument.class);
|
|
59 |
/**
|
|
60 |
*
|
|
61 |
*/
|
|
62 |
private static final long serialVersionUID = 676711512482334764L;
|
|
67 | 63 |
|
68 |
public static final String PERSISTENCE_DEFINITION_NAME = "DefaultViewDocument";
|
|
69 |
|
|
64 |
public static final String PERSISTENCE_DEFINITION_NAME = "DefaultViewDocument";
|
|
65 |
|
|
70 | 66 |
private class SetViewPortExtentWhenAddLayerListener extends BaseLayerCollectionListener { |
71 | 67 |
|
72 | 68 |
private Thread th = null; |
73 | 69 |
private final ViewPort viewPort; |
74 |
|
|
70 |
|
|
75 | 71 |
public SetViewPortExtentWhenAddLayerListener(ViewPort viewPort) { |
76 | 72 |
this.viewPort = viewPort; |
77 | 73 |
} |
78 |
|
|
74 |
|
|
79 | 75 |
@Override |
80 | 76 |
public synchronized void layerAdded(LayerCollectionEvent e) { |
81 |
if( th != null ) {
|
|
77 |
if (th != null) {
|
|
82 | 78 |
return; |
83 | 79 |
} |
84 | 80 |
if (viewPort.getEnvelope() == null) { |
85 | 81 |
final FLayer layer = e.getAffectedLayer(); |
86 |
if (layer.isAvailable() ) {
|
|
82 |
if (layer.isAvailable()) {
|
|
87 | 83 |
th = new Thread(new Runnable() { |
88 | 84 |
@Override |
89 | 85 |
public void run() { |
... | ... | |
91 | 87 |
ApplicationManager application = ApplicationLocator.getManager(); |
92 | 88 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
93 | 89 |
application.message( |
94 |
i18n.getTranslation("_Calculating_envelope"), |
|
95 |
JOptionPane.INFORMATION_MESSAGE |
|
90 |
i18n.getTranslation("_Calculating_envelope"),
|
|
91 |
JOptionPane.INFORMATION_MESSAGE
|
|
96 | 92 |
); |
97 | 93 |
Envelope envelope = layer.getFullEnvelope(); |
98 | 94 |
// Si nadie le ha asignado un envelope mientras se |
... | ... | |
101 | 97 |
viewPort.setEnvelope(envelope); |
102 | 98 |
} |
103 | 99 |
application.message( |
104 |
"", |
|
105 |
JOptionPane.INFORMATION_MESSAGE |
|
100 |
"",
|
|
101 |
JOptionPane.INFORMATION_MESSAGE
|
|
106 | 102 |
); |
107 | 103 |
} catch (ReadException ex) { |
108 | 104 |
} |
... | ... | |
119 | 115 |
} |
120 | 116 |
} |
121 | 117 |
} |
122 |
|
|
118 |
|
|
123 | 119 |
} |
124 | 120 |
|
125 |
public DefaultViewDocument() { |
|
126 |
this(null); |
|
127 |
} |
|
128 |
|
|
129 |
public DefaultViewDocument(DocumentManager factory) { |
|
130 |
super(factory); |
|
121 |
public DefaultViewDocument() { |
|
122 |
this(null); |
|
123 |
} |
|
131 | 124 |
|
132 |
ViewPort vp; |
|
133 |
|
|
134 |
ProjectPreferences preferences = (ProjectPreferences) ApplicationLocator.getManager().getPreferences("project"); |
|
135 |
|
|
136 |
MapContext viewMapContext = new MapContext( |
|
137 |
new ViewPort( preferences.getDefaultProjection() ) |
|
138 |
); |
|
139 |
vp = viewMapContext.getViewPort(); |
|
140 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
141 |
vp.setDistanceUnits(preferences.getDefaultDistanceUnits()); |
|
142 |
vp.setDistanceArea(preferences.getDefaultDistanceArea()); |
|
143 |
|
|
144 |
/* |
|
125 |
public DefaultViewDocument(DocumentManager factory) { |
|
126 |
super(factory); |
|
127 |
|
|
128 |
ViewPort vp; |
|
129 |
|
|
130 |
ProjectPreferences preferences = (ProjectPreferences) ApplicationLocator.getManager().getPreferences("project"); |
|
131 |
|
|
132 |
MapContext viewMapContext = new MapContext( |
|
133 |
new ViewPort(preferences.getDefaultProjection()) |
|
134 |
); |
|
135 |
vp = viewMapContext.getViewPort(); |
|
136 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
137 |
vp.setDistanceUnits(preferences.getDefaultDistanceUnits()); |
|
138 |
vp.setDistanceArea(preferences.getDefaultDistanceArea()); |
|
139 |
|
|
140 |
/* |
|
145 | 141 |
* Another user preference: the order manager |
146 |
*/ |
|
147 |
LayerOrderManager lom = getCurrentOrderManager(); |
|
148 |
viewMapContext.setOrderManager(lom); |
|
149 |
|
|
150 |
|
|
151 |
/* |
|
142 |
*/ |
|
143 |
LayerOrderManager lom = getCurrentOrderManager(); |
|
144 |
viewMapContext.setOrderManager(lom); |
|
145 |
|
|
146 |
/* |
|
152 | 147 |
* Not very elegant but we are forcing meters if projected |
153 |
*/
|
|
154 |
if (viewMapContext.getProjection().isProjected()) {
|
|
155 |
vp.setMapUnits(1);
|
|
156 |
} else {
|
|
148 |
*/
|
|
149 |
if (viewMapContext.getProjection().isProjected()) {
|
|
150 |
vp.setMapUnits(1);
|
|
151 |
} else {
|
|
157 | 152 |
vp.setMapUnits(8); |
158 |
} |
|
159 |
|
|
160 |
|
|
161 |
this.setMapContext(viewMapContext); |
|
162 |
|
|
163 |
MapContext overviewMapContext = new MapContext( |
|
164 |
new ViewPort( viewMapContext.getProjection() ) |
|
165 |
); |
|
166 |
vp = viewMapContext.getViewPort(); |
|
167 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
168 |
this.setMapOverViewContext(overviewMapContext); |
|
169 |
|
|
153 |
} |
|
154 |
|
|
155 |
this.setMapContext(viewMapContext); |
|
156 |
|
|
157 |
MapContext overviewMapContext = new MapContext( |
|
158 |
new ViewPort(viewMapContext.getProjection()) |
|
159 |
); |
|
160 |
vp = viewMapContext.getViewPort(); |
|
161 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
162 |
this.setMapOverViewContext(overviewMapContext); |
|
163 |
|
|
170 | 164 |
this.getMapContext().getLayers().addLayerCollectionListener( |
171 |
new SetViewPortExtentWhenAddLayerListener(this.getMapContext().getViewPort()) |
|
165 |
new SetViewPortExtentWhenAddLayerListener(this.getMapContext().getViewPort())
|
|
172 | 166 |
); |
173 | 167 |
this.getMapOverViewContext().getLayers().addLayerCollectionListener( |
174 |
new SetViewPortExtentWhenAddLayerListener(this.getMapOverViewContext().getViewPort()) |
|
168 |
new SetViewPortExtentWhenAddLayerListener(this.getMapOverViewContext().getViewPort())
|
|
175 | 169 |
); |
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
* Get current order manager from persistence
|
|
180 |
*
|
|
181 |
* @return
|
|
182 |
*/
|
|
183 |
private LayerOrderManager getCurrentOrderManager() {
|
|
184 |
|
|
185 |
DynObject props = this.getPluginProperties();
|
|
186 |
// current_layer_order_manager
|
|
187 |
Object val_obj = null;
|
|
188 |
if (props.hasDynValue(LayerOrderPage.PREFERENCES_ID)) {
|
|
189 |
val_obj = props.getDynValue(LayerOrderPage.PREFERENCES_ID);
|
|
190 |
}
|
|
191 |
if (val_obj != null && val_obj instanceof LayerOrderManager) {
|
|
192 |
LayerOrderManager lom = (LayerOrderManager) val_obj;
|
|
193 |
return lom;
|
|
194 |
} else {
|
|
195 |
logger.info("No order manager found in persistence.");
|
|
196 |
return MapContextLocator.getDefaultOrderManager();
|
|
197 |
}
|
|
198 |
|
|
199 |
}
|
|
200 |
|
|
201 |
private DynObject getPluginProperties() {
|
|
170 |
}
|
|
171 |
|
|
172 |
/**
|
|
173 |
* Get current order manager from persistence
|
|
174 |
*
|
|
175 |
* @return
|
|
176 |
*/
|
|
177 |
private LayerOrderManager getCurrentOrderManager() {
|
|
178 |
|
|
179 |
DynObject props = this.getPluginProperties();
|
|
180 |
// current_layer_order_manager
|
|
181 |
Object val_obj = null;
|
|
182 |
if (props.hasDynValue(LayerOrderPage.PREFERENCES_ID)) {
|
|
183 |
val_obj = props.getDynValue(LayerOrderPage.PREFERENCES_ID);
|
|
184 |
}
|
|
185 |
if (val_obj != null && val_obj instanceof LayerOrderManager) {
|
|
186 |
LayerOrderManager lom = (LayerOrderManager) val_obj;
|
|
187 |
return lom;
|
|
188 |
} else {
|
|
189 |
logger.info("No order manager found in persistence.");
|
|
190 |
return MapContextLocator.getDefaultOrderManager();
|
|
191 |
}
|
|
192 |
|
|
193 |
}
|
|
194 |
|
|
195 |
private DynObject getPluginProperties() {
|
|
202 | 196 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
203 | 197 |
return pluginsManager.getPlugin(AddLayer.class).getPluginProperties(); |
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
208 |
super.saveToState(state); |
|
209 |
} |
|
210 |
|
|
211 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
212 |
super.loadFromState(state); |
|
213 |
} |
|
198 |
} |
|
214 | 199 |
|
215 |
public String exportDocumentAsText() { |
|
216 |
// FIXME: jjdc PersistentManager getStateAsText o similar |
|
200 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
201 |
super.saveToState(state); |
|
202 |
} |
|
203 |
|
|
204 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
205 |
super.loadFromState(state); |
|
206 |
} |
|
207 |
|
|
208 |
public String exportDocumentAsText() { |
|
209 |
// FIXME: jjdc PersistentManager getStateAsText o similar |
|
217 | 210 |
// PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
218 | 211 |
// PersistentState state = manager.getState(this); |
219 | 212 |
// return manager.getStateAsText(state); |
220 |
return null;
|
|
221 |
}
|
|
213 |
return null;
|
|
214 |
}
|
|
222 | 215 |
|
223 |
public void setStateFromText(String text) {
|
|
224 |
// FIXME: jjdc PersistentManager getStateFromText o similar
|
|
216 |
public void setStateFromText(String text) {
|
|
217 |
// FIXME: jjdc PersistentManager getStateFromText o similar
|
|
225 | 218 |
// PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
226 | 219 |
// PersistentState state = manager.getStateFromText(text); |
227 | 220 |
// this.loadFromState(state); |
228 |
}
|
|
221 |
}
|
|
229 | 222 |
|
230 |
|
|
231 | 223 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/develtools/PersistenceDevelTool.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.app.extension.develtools; |
25 | 25 |
|
26 |
import java.lang.reflect.Method; |
|
26 | 27 |
import java.util.ArrayList; |
27 | 28 |
import java.util.Collections; |
28 | 29 |
import java.util.Comparator; |
29 | 30 |
import java.util.List; |
30 | 31 |
import java.util.Set; |
31 | 32 |
import java.util.TreeSet; |
33 |
import java.util.logging.Level; |
|
32 | 34 |
|
33 | 35 |
import org.gvsig.tools.ToolsLocator; |
34 | 36 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
... | ... | |
37 | 39 |
import org.gvsig.tools.persistence.PersistenceFactory; |
38 | 40 |
import org.gvsig.tools.persistence.PersistenceManager; |
39 | 41 |
import org.gvsig.tools.persistence.Persistent; |
42 |
import org.gvsig.tools.persistence.PersistentState; |
|
40 | 43 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
41 | 44 |
import org.slf4j.Logger; |
42 | 45 |
import org.slf4j.LoggerFactory; |
43 | 46 |
|
44 | 47 |
public class PersistenceDevelTool { |
45 |
private static Logger logger = LoggerFactory.getLogger(PersistenceDevelTool.class); |
|
46 | 48 |
|
47 |
public void showPersistenceFactories() { |
|
48 |
String html = this.getPersistenceFactories(); |
|
49 |
InfoPanel.save2file("persistenceinfo", html); |
|
50 |
InfoPanel.showPanel("Persistence factories", WindowManager.MODE.WINDOW, html); |
|
51 |
} |
|
52 |
|
|
49 |
private static Logger logger = LoggerFactory.getLogger(PersistenceDevelTool.class); |
|
53 | 50 |
|
54 |
public class PersistenceInfo implements Comparable<PersistenceInfo> {
|
|
55 |
PersistenceFactory factory;
|
|
56 |
@SuppressWarnings("rawtypes")
|
|
57 |
Class theClass;
|
|
58 |
DynStruct definition;
|
|
51 |
public void showPersistenceFactories() {
|
|
52 |
String html = this.getPersistenceFactories();
|
|
53 |
InfoPanel.save2file("persistenceinfo", html);
|
|
54 |
InfoPanel.showPanel("Persistence factories", WindowManager.MODE.WINDOW, html);
|
|
55 |
}
|
|
59 | 56 |
|
60 |
PersistenceInfo(PersistenceFactory factory, |
|
61 |
@SuppressWarnings("rawtypes") Class theClass, |
|
62 |
DynStruct definition) { |
|
63 |
this.factory = factory; |
|
64 |
this.theClass = theClass; |
|
65 |
this.definition = definition; |
|
66 |
} |
|
57 |
public class PersistenceInfo implements Comparable<PersistenceInfo> { |
|
67 | 58 |
|
68 |
String getDefinitionName() { |
|
69 |
if (definition == null) { |
|
70 |
return ""; |
|
71 |
} |
|
72 |
return definition.getFullName(); |
|
73 |
} |
|
59 |
PersistenceFactory factory; |
|
60 |
@SuppressWarnings("rawtypes") |
|
61 |
Class theClass; |
|
62 |
DynStruct definition; |
|
74 | 63 |
|
75 |
String getDefinitionDescription() { |
|
76 |
if (definition == null) { |
|
77 |
return ""; |
|
78 |
} |
|
79 |
return definition.getDescription(); |
|
80 |
} |
|
64 |
PersistenceInfo(PersistenceFactory factory, |
|
65 |
@SuppressWarnings("rawtypes") Class theClass, |
|
66 |
DynStruct definition) { |
|
67 |
this.factory = factory; |
|
68 |
this.theClass = theClass; |
|
69 |
this.definition = definition; |
|
70 |
} |
|
81 | 71 |
|
82 |
String getClassName() { |
|
83 |
if (theClass == null) { |
|
84 |
return ""; |
|
85 |
} |
|
86 |
return theClass.getName(); |
|
87 |
} |
|
72 |
boolean hasSaveToState() { |
|
73 |
try { |
|
74 |
Method method = theClass.getMethod("saveToState", PersistentState.class); |
|
75 |
if (method == null) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
} catch (NoSuchMethodException | SecurityException ex) { |
|
79 |
return false; |
|
80 |
} |
|
81 |
return true; |
|
82 |
} |
|
88 | 83 |
|
89 |
String getFactoryName() { |
|
90 |
if (factory == null) { |
|
91 |
return ""; |
|
92 |
} |
|
93 |
return factory.getClass().getName(); |
|
94 |
} |
|
84 |
boolean hasLoadFromState() { |
|
85 |
try { |
|
86 |
Method method = theClass.getMethod("loadFromState", PersistentState.class); |
|
87 |
if (method == null) { |
|
88 |
return false; |
|
89 |
} |
|
90 |
} catch (NoSuchMethodException | SecurityException ex) { |
|
91 |
return false; |
|
92 |
} |
|
93 |
return true; |
|
94 |
} |
|
95 | 95 |
|
96 |
public int compareTo(PersistenceInfo other) { |
|
97 |
int r = this.factory.getClass().getName() |
|
98 |
.compareTo(other.factory.getClass().getName()); |
|
99 |
if (r == 0) { |
|
100 |
return this.theClass.getName().compareTo( |
|
101 |
other.theClass.getName()); |
|
102 |
} |
|
103 |
return r; |
|
104 |
} |
|
105 |
} |
|
96 |
String getDefinitionName() { |
|
97 |
if (definition == null) { |
|
98 |
return ""; |
|
99 |
} |
|
100 |
return definition.getFullName(); |
|
101 |
} |
|
106 | 102 |
|
107 |
@SuppressWarnings("rawtypes") |
|
108 |
public class ClassComparator implements Comparator { |
|
103 |
String getDefinitionDescription() { |
|
104 |
if (definition == null) { |
|
105 |
return ""; |
|
106 |
} |
|
107 |
return definition.getDescription(); |
|
108 |
} |
|
109 | 109 |
|
110 |
public int compare(Object o1, Object o2) { |
|
111 |
if (o1 == null || o2 == null || ((Class) o1).getName() == null) { |
|
112 |
logger.warn("Esto no deberia estar pasando."); |
|
113 |
return 0; // FIXME |
|
114 |
} |
|
115 |
return ((Class) o1).getName().compareTo(((Class) o2).getName()); |
|
116 |
} |
|
110 |
String getClassName() { |
|
111 |
if (theClass == null) { |
|
112 |
return ""; |
|
113 |
} |
|
114 |
return theClass.getName(); |
|
115 |
} |
|
117 | 116 |
|
118 |
} |
|
117 |
String getFactoryName() { |
|
118 |
if (factory == null) { |
|
119 |
return ""; |
|
120 |
} |
|
121 |
return factory.getClass().getName(); |
|
122 |
} |
|
119 | 123 |
|
120 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
121 |
public String getPersistenceFactories() { |
|
122 |
int warningsCounter = 0; |
|
123 |
List<PersistenceInfo> classes = new ArrayList<PersistenceInfo>(); |
|
124 |
Set<Class> referencedClasses = new TreeSet<Class>(new ClassComparator()); |
|
124 |
public int compareTo(PersistenceInfo other) { |
|
125 |
int r = this.factory.getClass().getName() |
|
126 |
.compareTo(other.factory.getClass().getName()); |
|
127 |
if (r == 0) { |
|
128 |
return this.theClass.getName().compareTo( |
|
129 |
other.theClass.getName()); |
|
130 |
} |
|
131 |
return r; |
|
132 |
} |
|
133 |
} |
|
125 | 134 |
|
126 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
135 |
@SuppressWarnings("rawtypes") |
|
136 |
public class ClassComparator implements Comparator { |
|
127 | 137 |
|
128 |
List<PersistenceFactory> factories = manager.getFactories(); |
|
129 |
for (PersistenceFactory factory : factories) { |
|
130 |
List<Class> theClasses = factory.getManagedClasses(); |
|
131 |
for (Class theClass : theClasses) { |
|
138 |
public int compare(Object o1, Object o2) { |
|
139 |
if (o1 == null || o2 == null || ((Class) o1).getName() == null) { |
|
140 |
logger.warn("Esto no deberia estar pasando."); |
|
141 |
return 0; // FIXME |
|
142 |
} |
|
143 |
return ((Class) o1).getName().compareTo(((Class) o2).getName()); |
|
144 |
} |
|
132 | 145 |
|
133 |
DynStruct definition = manager.getDefinition(theClass); |
|
134 |
List defs = factory.getDefinitions(); |
|
135 |
if (definition == null && defs != null && !defs.isEmpty()) { |
|
136 |
for (int i = 0; i < defs.size(); i++) { |
|
137 |
definition = (DynStruct) defs.get(i); |
|
138 |
classes.add(new PersistenceInfo(factory, theClass, |
|
139 |
definition)); |
|
140 |
} |
|
141 |
} else { |
|
142 |
classes.add(new PersistenceInfo(factory, theClass, |
|
143 |
definition)); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
Collections.sort(classes); |
|
146 |
} |
|
148 | 147 |
|
149 |
StringBuffer buffer = new StringBuffer(); |
|
150 |
StringBuffer warnings = new StringBuffer(); |
|
148 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
149 |
public String getPersistenceFactories() { |
|
150 |
int warningsCounter = 0; |
|
151 |
List<PersistenceInfo> classes = new ArrayList<PersistenceInfo>(); |
|
152 |
Set<Class> referencedClasses = new TreeSet<Class>(new ClassComparator()); |
|
151 | 153 |
|
152 |
buffer.append("<html>\n"); |
|
153 |
buffer.append("<body>\n"); |
|
154 |
buffer.append("<h2>Supported persistent classes</h2>\n"); |
|
155 |
buffer.append("<br>\n"); |
|
154 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
156 | 155 |
|
157 |
buffer.append("<ol>\n"); |
|
158 |
for (PersistenceInfo classInfo : classes) { |
|
159 |
StringBuffer classBuffer = new StringBuffer(); |
|
160 |
boolean warning = false; |
|
161 |
classBuffer.append(" <li>\n "); |
|
162 |
classBuffer.append("Class: <i>"); |
|
163 |
classBuffer.append(classInfo.getClassName()); |
|
164 |
classBuffer.append("</i><br>\n Persistent: <i>"); |
|
165 |
if (Persistent.class.isAssignableFrom(classInfo.theClass)) { |
|
166 |
classBuffer.append(" yes."); |
|
167 |
} else { |
|
168 |
classBuffer.append(" through a factory."); |
|
169 |
} |
|
170 |
classBuffer.append("<br>\n Factory: <i>"); |
|
171 |
classBuffer.append(classInfo.getFactoryName()).append( |
|
172 |
"</i><br>\n Definition name: <i>"); |
|
173 |
classBuffer.append(classInfo.getDefinitionName()).append( |
|
174 |
"</i><br>\n Description: \n"); |
|
175 |
classBuffer.append(classInfo.getDefinitionDescription()).append( |
|
176 |
"<br>\n "); |
|
177 |
DataTypesManager dataTypesManager = ToolsLocator |
|
178 |
.getDataTypesManager(); |
|
179 |
DynStruct definition = classInfo.definition; |
|
180 |
if (definition == null) { |
|
181 |
classBuffer.append("Definition for ") |
|
182 |
.append(classInfo.getClassName()) |
|
183 |
.append(" is null.<br>\n "); |
|
184 |
warningsCounter++; |
|
185 |
warning = true; |
|
186 |
} else { |
|
187 |
DynField[] fields = definition.getDynFields(); |
|
188 |
for (int i = 0; i < fields.length; i++) { |
|
189 |
DynField field = fields[i]; |
|
190 |
if (dataTypesManager.isContainer(field.getType())) { |
|
191 |
if (field.getClassOfItems() == null) { |
|
192 |
classBuffer |
|
193 |
.append("Field <b>") |
|
194 |
.append(field.getName()) |
|
195 |
.append("</b> as container (") |
|
196 |
.append(field.getDataType().getName()) |
|
197 |
.append("), can't has class for value of items.<br>\n "); |
|
198 |
warningsCounter++; |
|
199 |
warning = true; |
|
200 |
} else { |
|
201 |
classBuffer.append("Field ") |
|
202 |
.append(field.getName()) |
|
203 |
.append(" as container (") |
|
204 |
.append(field.getDataType().getName()) |
|
205 |
.append(") of '") |
|
206 |
.append(field.getClassOfItems().getName()) |
|
207 |
.append("'.<br>\n "); |
|
208 |
referencedClasses.add(field.getClassOfItems()); |
|
209 |
} |
|
210 |
} else if (dataTypesManager.isObject(field.getType())) { |
|
211 |
if (field.getClassOfValue() == null) { |
|
212 |
classBuffer |
|
213 |
.append("Field <b>") |
|
214 |
.append(field.getName()) |
|
215 |
.append(" as object </b> can't has class of value.<br>\n "); |
|
216 |
warningsCounter++; |
|
217 |
warning = true; |
|
218 |
} else { |
|
219 |
classBuffer.append("Field ") |
|
220 |
.append(field.getName()).append(" as object '") |
|
221 |
.append(field.getClassOfValue()) |
|
222 |
.append("'.<br>\n "); |
|
223 |
referencedClasses.add(field.getClassOfValue()); |
|
224 |
} |
|
225 |
} else { |
|
226 |
classBuffer.append("Field ") |
|
227 |
.append(field.getName()).append(" as '") |
|
228 |
.append(field.getDataType().getName()) |
|
229 |
.append("'.<br>\n "); |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
classBuffer.append("<br>\n </li>\n"); |
|
234 |
buffer.append(classBuffer); |
|
235 |
if (warning) { |
|
236 |
warnings.append(classBuffer); |
|
237 |
} |
|
238 |
} |
|
239 |
buffer.append("</ol>\n"); |
|
240 |
buffer.append("<br>\n"); |
|
241 |
buffer.append("<br>\n"); |
|
156 |
List<PersistenceFactory> factories = manager.getFactories(); |
|
157 |
for (PersistenceFactory factory : factories) { |
|
158 |
List<Class> theClasses = factory.getManagedClasses(); |
|
159 |
for (Class theClass : theClasses) { |
|
242 | 160 |
|
243 |
buffer.append("<h2>Persistent classes with problems</h2>\n"); |
|
244 |
buffer.append("<ol>\n"); |
|
245 |
buffer.append(warnings); |
|
246 |
buffer.append("</ol>\n"); |
|
247 |
buffer.append("<br>\n<p>Total warnigs: ").append(warningsCounter) |
|
248 |
.append("</p>"); |
|
161 |
DynStruct definition = manager.getDefinition(theClass); |
|
162 |
List defs = factory.getDefinitions(); |
|
163 |
if (definition == null && defs != null && !defs.isEmpty()) { |
|
164 |
for (int i = 0; i < defs.size(); i++) { |
|
165 |
definition = (DynStruct) defs.get(i); |
|
166 |
classes.add(new PersistenceInfo(factory, theClass, |
|
167 |
definition)); |
|
168 |
} |
|
169 |
} else { |
|
170 |
classes.add(new PersistenceInfo(factory, theClass, |
|
171 |
definition)); |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
Collections.sort(classes); |
|
249 | 176 |
|
250 |
buffer.append("<h2>Not persistents used classes</h2>\n"); |
|
251 |
buffer.append("<ol>\n"); |
|
252 |
for (Class theClass : referencedClasses) { |
|
253 |
// if( manager.canPersist(theClass) ) { |
|
254 |
// continue; |
|
255 |
// } |
|
256 |
if (Persistent.class.isAssignableFrom(theClass)) { |
|
257 |
continue; |
|
258 |
} |
|
259 |
if (manager.getFactories().get(theClass) != null) { |
|
260 |
continue; |
|
261 |
} |
|
262 |
buffer.append(" <li>\n"); |
|
263 |
buffer.append(" <i>").append(theClass.getName()) |
|
264 |
.append("</i><br>\n"); |
|
265 |
buffer.append(" </li>\n"); |
|
266 |
warningsCounter++; |
|
267 |
} |
|
268 |
buffer.append("</ol>\n"); |
|
177 |
StringBuffer buffer = new StringBuffer(); |
|
178 |
StringBuffer warnings = new StringBuffer(); |
|
269 | 179 |
|
270 |
buffer.append("</body>\n"); |
|
271 |
buffer.append("</html>\n"); |
|
180 |
buffer.append("<html>\n"); |
|
181 |
buffer.append("<body>\n"); |
|
182 |
buffer.append("<h2>Supported persistent classes</h2>\n"); |
|
183 |
buffer.append("<br>\n"); |
|
272 | 184 |
|
273 |
return buffer.toString(); |
|
274 |
} |
|
185 |
buffer.append("<ol>\n"); |
|
186 |
for (PersistenceInfo classInfo : classes) { |
|
187 |
StringBuffer classBuffer = new StringBuffer(); |
|
188 |
boolean warning = false; |
|
189 |
classBuffer.append(" <li>\n "); |
|
190 |
classBuffer.append("Class: <i>"); |
|
191 |
classBuffer.append(classInfo.getClassName()); |
|
192 |
classBuffer.append("</i><br>\n Persistent: <i>"); |
|
275 | 193 |
|
194 |
if (Persistent.class.isAssignableFrom(classInfo.theClass)) { |
|
195 |
classBuffer.append(" yes."); |
|
196 |
if (!classInfo.hasSaveToState()) { |
|
197 |
classBuffer.append("<br>\n <b>This class doesn't implement saveToState</b>"); |
|
198 |
warningsCounter++; |
|
199 |
warning = true; |
|
200 |
} |
|
201 |
if (!classInfo.hasLoadFromState()) { |
|
202 |
classBuffer.append("<br>\n <b>This class doesn't implement loadFromState</b>"); |
|
203 |
warningsCounter++; |
|
204 |
warning = true; |
|
205 |
} |
|
206 |
} else { |
|
207 |
classBuffer.append(" through a factory."); |
|
208 |
} |
|
276 | 209 |
|
210 |
classBuffer.append("<br>\n Factory: <i>"); |
|
211 |
classBuffer.append(classInfo.getFactoryName()).append( |
|
212 |
"</i><br>\n Definition name: <i>"); |
|
213 |
classBuffer.append(classInfo.getDefinitionName()).append( |
|
214 |
"</i><br>\n Description: \n"); |
|
215 |
classBuffer.append(classInfo.getDefinitionDescription()).append( |
|
216 |
"<br>\n "); |
|
217 |
DataTypesManager dataTypesManager = ToolsLocator |
|
218 |
.getDataTypesManager(); |
|
219 |
DynStruct definition = classInfo.definition; |
|
220 |
if (definition == null) { |
|
221 |
classBuffer.append("Definition for ") |
|
222 |
.append(classInfo.getClassName()) |
|
223 |
.append(" is null.<br>\n "); |
|
224 |
warningsCounter++; |
|
225 |
warning = true; |
|
226 |
} else { |
|
227 |
DynField[] fields = definition.getDynFields(); |
|
228 |
for (int i = 0; i < fields.length; i++) { |
|
229 |
DynField field = fields[i]; |
|
230 |
if (dataTypesManager.isContainer(field.getType())) { |
|
231 |
if (field.getClassOfItems() == null) { |
|
232 |
classBuffer |
|
233 |
.append("Field <b>") |
|
234 |
.append(field.getName()) |
|
235 |
.append("</b> as container (") |
|
236 |
.append(field.getDataType().getName()) |
|
237 |
.append("), can't has class for value of items.<br>\n "); |
|
238 |
warningsCounter++; |
|
239 |
warning = true; |
|
240 |
} else { |
|
241 |
classBuffer.append("Field ") |
|
242 |
.append(field.getName()) |
|
243 |
.append(" as container (") |
|
244 |
.append(field.getDataType().getName()) |
|
245 |
.append(") of '") |
|
246 |
.append(field.getClassOfItems().getName()) |
|
247 |
.append("'.<br>\n "); |
|
248 |
referencedClasses.add(field.getClassOfItems()); |
|
249 |
} |
|
250 |
} else if (dataTypesManager.isObject(field.getType())) { |
|
251 |
if (field.getClassOfValue() == null) { |
|
252 |
classBuffer |
|
253 |
.append("Field <b>") |
|
254 |
.append(field.getName()) |
|
255 |
.append(" as object </b> can't has class of value.<br>\n "); |
|
256 |
warningsCounter++; |
|
257 |
warning = true; |
|
258 |
} else { |
|
259 |
classBuffer.append("Field ") |
|
260 |
.append(field.getName()).append(" as object '") |
|
261 |
.append(field.getClassOfValue()) |
|
262 |
.append("'.<br>\n "); |
|
263 |
referencedClasses.add(field.getClassOfValue()); |
|
264 |
} |
|
265 |
} else { |
|
266 |
classBuffer.append("Field ") |
|
267 |
.append(field.getName()).append(" as '") |
|
268 |
.append(field.getDataType().getName()) |
|
269 |
.append("'.<br>\n "); |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
classBuffer.append("<br>\n </li>\n"); |
|
274 |
buffer.append(classBuffer); |
|
275 |
if (warning) { |
|
276 |
warnings.append(classBuffer); |
|
277 |
} |
|
278 |
} |
|
279 |
buffer.append("</ol>\n"); |
|
280 |
buffer.append("<br>\n"); |
|
281 |
buffer.append("<br>\n"); |
|
282 |
|
|
283 |
buffer.append("<h2>Persistent classes with problems</h2>\n"); |
|
284 |
buffer.append("<ol>\n"); |
|
285 |
buffer.append(warnings); |
|
286 |
buffer.append("</ol>\n"); |
|
287 |
buffer.append("<br>\n<p>Total warnigs: ").append(warningsCounter) |
|
288 |
.append("</p>"); |
|
289 |
|
|
290 |
buffer.append("<h2>Not persistents used classes</h2>\n"); |
|
291 |
buffer.append("<ol>\n"); |
|
292 |
for (Class theClass : referencedClasses) { |
|
293 |
// if( manager.canPersist(theClass) ) { |
|
294 |
// continue; |
|
295 |
// } |
|
296 |
if (Persistent.class.isAssignableFrom(theClass)) { |
|
297 |
continue; |
|
298 |
} |
|
299 |
if (manager.getFactories().get(theClass) != null) { |
|
300 |
continue; |
|
301 |
} |
|
302 |
buffer.append(" <li>\n"); |
|
303 |
buffer.append(" <i>").append(theClass.getName()) |
|
304 |
.append("</i><br>\n"); |
|
305 |
buffer.append(" </li>\n"); |
|
306 |
warningsCounter++; |
|
307 |
} |
|
308 |
buffer.append("</ol>\n"); |
|
309 |
|
|
310 |
buffer.append("</body>\n"); |
|
311 |
buffer.append("</html>\n"); |
|
312 |
|
|
313 |
return buffer.toString(); |
|
314 |
} |
|
315 |
|
|
277 | 316 |
} |
Also available in: Unified diff