svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / dataStoreParameters / DefaultDataStoreParametersPanelManager.java @ 46485
History | View | Annotate | Download (4.84 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.dataStoreParameters; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.util.ArrayList; |
6 |
import java.util.List; |
7 |
import org.apache.commons.lang3.StringUtils; |
8 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel; |
9 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelFactory; |
10 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager; |
11 |
import org.gvsig.tools.ToolsLocator; |
12 |
import org.gvsig.tools.dynobject.DynObject; |
13 |
import org.gvsig.tools.i18n.I18nManager; |
14 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
15 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
16 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
17 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
18 |
import org.slf4j.Logger; |
19 |
import org.slf4j.LoggerFactory; |
20 |
|
21 |
|
22 |
public class DefaultDataStoreParametersPanelManager implements DataStoreParametersPanelManager { |
23 |
|
24 |
private static Logger logger = LoggerFactory.getLogger(DefaultDataStoreParametersPanelManager.class); |
25 |
|
26 |
private List<DataStoreParametersPanelFactory> factories = null; |
27 |
|
28 |
public DefaultDataStoreParametersPanelManager() {
|
29 |
this.factories = new ArrayList<>(); |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public void registerFactory(DataStoreParametersPanelFactory factory) { |
34 |
if( this.factories.contains(factory) ) { |
35 |
return;
|
36 |
} |
37 |
this.factories.add(factory);
|
38 |
} |
39 |
|
40 |
@Override
|
41 |
public DataStoreParametersPanelFactory getFactory(DynObject parameters) {
|
42 |
DataStoreParametersPanelFactory factory = null;
|
43 |
for (DataStoreParametersPanelFactory currentFactory : factories) {
|
44 |
if( currentFactory.canBeApplied(parameters) ) {
|
45 |
if( factory == null ) { |
46 |
factory = currentFactory; |
47 |
} else if( factory.getPriority() < currentFactory.getPriority() ) { |
48 |
factory = currentFactory; |
49 |
} |
50 |
} |
51 |
} |
52 |
return factory;
|
53 |
} |
54 |
|
55 |
@Override
|
56 |
public DataStoreParametersPanel createDataStoreParametersPanel(DynObject parameters) {
|
57 |
DataStoreParametersPanelFactory factory = this.getFactory(parameters);
|
58 |
if( factory == null ) { |
59 |
return null; |
60 |
} |
61 |
return factory.create(parameters);
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public int showPropertiesDialog(final DynObject parameters) { |
66 |
|
67 |
final DataStoreParametersPanel panel = this.createDataStoreParametersPanel(parameters); |
68 |
return this.showPropertiesDialog(parameters, panel); |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public int showPropertiesDialog(final DynObject parameters, final DataStoreParametersPanel panel) { |
73 |
return this.showPropertiesDialog(parameters, panel, WindowManager.MODE.DIALOG); |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public int showPropertiesDialog(final DynObject parameters, final DataStoreParametersPanel panel, WindowManager.MODE showMode) { |
78 |
Dialog dialog = this.createPropertiesDialog(parameters, panel); |
79 |
dialog.addActionListener((ActionEvent ae) -> {
|
80 |
switch(ae.getID() ) {
|
81 |
case WindowManager_v2.BUTTON_APPLY:
|
82 |
showAdvancedPropertiesDialog(parameters); |
83 |
break;
|
84 |
case WindowManager_v2.BUTTON_OK:
|
85 |
panel.fetchParameters(parameters); |
86 |
break;
|
87 |
case WindowManager_v2.BUTTON_CANCEL:
|
88 |
break;
|
89 |
} |
90 |
}); |
91 |
dialog.show(showMode); |
92 |
return dialog.getAction();
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public Dialog createPropertiesDialog(final DynObject parameters, final DataStoreParametersPanel panel) { |
97 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
98 |
|
99 |
String title = parameters.getDynClass().getDescription();
|
100 |
if( StringUtils.isBlank(title) ) {
|
101 |
title = parameters.getDynClass().getName(); |
102 |
} |
103 |
if( title.startsWith("_") ) { |
104 |
title = i18n.getTranslation(title); |
105 |
} |
106 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
107 |
Dialog dialog = winmanager.createDialog(
|
108 |
panel.asJComponent(), |
109 |
title, |
110 |
null,
|
111 |
WindowManager_v2.BUTTONS_APPLY_OK_CANCEL |
112 |
); |
113 |
if( panel instanceof DataStoreDynObjectParametersPanel ) { |
114 |
dialog.setButtons(WindowManager_v2.BUTTONS_OK_CANCEL); |
115 |
} else {
|
116 |
dialog.setButtonLabel( |
117 |
WindowManager_v2.BUTTON_APPLY, |
118 |
i18n.getTranslation("Avanzado")
|
119 |
); |
120 |
} |
121 |
return dialog;
|
122 |
} |
123 |
|
124 |
@Override
|
125 |
public void showAdvancedPropertiesDialog(DynObject parameters) { |
126 |
final DataStoreParametersPanel panel = new DataStoreDynObjectParametersPanel(parameters); |
127 |
this.showPropertiesDialog(parameters, panel);
|
128 |
} |
129 |
} |