svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / DefaultExportPanelsManager.java @ 44270
History | View | Annotate | Download (3.56 KB)
1 |
package org.gvsig.export.swing.impl; |
---|---|
2 |
|
3 |
import java.lang.reflect.Constructor; |
4 |
import java.util.HashMap; |
5 |
import java.util.Map; |
6 |
import org.gvsig.export.ExportParameters; |
7 |
import org.gvsig.export.swing.JExportProcessPanel; |
8 |
import org.gvsig.export.swing.impl.panels.CheckGeometriesPanel; |
9 |
import org.gvsig.export.swing.impl.panels.SelectFilterPanel; |
10 |
import org.gvsig.export.swing.impl.panels.SelectGeometryTypePanel; |
11 |
import org.gvsig.export.swing.impl.panels.SelectOutputFilePanel; |
12 |
import org.gvsig.export.swing.impl.panels.SelectTargetProjectionPanel; |
13 |
import org.gvsig.export.swing.impl.panels.SelectGeometryFieldPanel; |
14 |
import org.gvsig.export.swing.impl.panels.SelectAttributesPanel; |
15 |
import org.gvsig.export.swing.spi.ExportPanel; |
16 |
import org.gvsig.export.swing.spi.ExportPanelsFactory; |
17 |
import org.gvsig.export.swing.spi.ExportPanelsManager; |
18 |
import org.slf4j.Logger; |
19 |
import org.slf4j.LoggerFactory; |
20 |
|
21 |
/**
|
22 |
*
|
23 |
* @author jjdelcerro
|
24 |
*/
|
25 |
public class DefaultExportPanelsManager |
26 |
implements ExportPanelsManager {
|
27 |
|
28 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultExportPanelsManager.class); |
29 |
|
30 |
private final Map<String, ExportPanelsFactory> factories; |
31 |
private final Map<String, Class<? extends ExportPanel>> stdPanels; |
32 |
|
33 |
public DefaultExportPanelsManager() {
|
34 |
super();
|
35 |
this.factories = new HashMap<>(); |
36 |
this.stdPanels = new HashMap(); |
37 |
this.stdPanels.put(PANEL_CHECK_GEOMETRIES, CheckGeometriesPanel.class);
|
38 |
this.stdPanels.put(PANEL_SELECT_FILTER, SelectFilterPanel.class);
|
39 |
this.stdPanels.put(PANEL_ATTRIBUTES_SELECTION, SelectAttributesPanel.class);
|
40 |
this.stdPanels.put(PANEL_SELECT_GEOMETRY_TYPE, SelectGeometryTypePanel.class);
|
41 |
this.stdPanels.put(PANEL_SELECT_OUTPUT_FILE, SelectOutputFilePanel.class);
|
42 |
this.stdPanels.put(PANEL_SELECT_TARGET_PROJECTION, SelectTargetProjectionPanel.class);
|
43 |
this.stdPanels.put(PANEL_SELECT_GEOMETRY_FIELD, SelectGeometryFieldPanel.class);
|
44 |
|
45 |
|
46 |
} |
47 |
|
48 |
@Override
|
49 |
public ExportPanelsFactory getPanelsFactory(String name) { |
50 |
ExportPanelsFactory factory = this.factories.get(name);
|
51 |
if (factory == null) { |
52 |
throw new IllegalArgumentException("Don't exists export panels factory '" + name + "'."); |
53 |
} |
54 |
return factory;
|
55 |
} |
56 |
|
57 |
@Override
|
58 |
public void register(ExportPanelsFactory factory) { |
59 |
this.factories.put(factory.getName(), factory);
|
60 |
} |
61 |
|
62 |
@Override
|
63 |
public ExportPanel createStandardPanel(
|
64 |
String panelId,
|
65 |
JExportProcessPanel processPanel, |
66 |
ExportParameters parameters, |
67 |
Object... args
|
68 |
) { |
69 |
Class<? extends ExportPanel> panelClass = this.stdPanels.get(panelId); |
70 |
if (panelClass == null) { |
71 |
throw new IllegalArgumentException("The panel '"+panelId+"' is not registered."); |
72 |
} |
73 |
Class[] classArgs = new Class[args.length + 2]; |
74 |
Object[] args2 = new Object[args.length + 2]; |
75 |
classArgs[0] = JExportProcessPanel.class;
|
76 |
classArgs[1] = ExportParameters.class;
|
77 |
args2[0] = processPanel;
|
78 |
args2[1] = parameters;
|
79 |
for (int i = 0; i < args.length; i++) { |
80 |
classArgs[i + 2] = args[i].getClass();
|
81 |
args2[i + 2] = args[i];
|
82 |
} |
83 |
try {
|
84 |
Constructor<? extends ExportPanel> constructor = panelClass.getConstructor(classArgs); |
85 |
ExportPanel panel = constructor.newInstance(args2); |
86 |
return panel;
|
87 |
} catch (Exception ex) { |
88 |
throw new IllegalArgumentException("Can't create a standard panel with id '" + panelId + "'.", ex); |
89 |
} |
90 |
} |
91 |
|
92 |
} |