svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / impl / DefaultFilesystemExplorerPropertiesPanelManager.java @ 42775
History | View | Annotate | Download (4.71 KB)
1 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing.impl; |
---|---|
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.serverexplorer.filesystem.swing.FilesystemExplorerPropertiesPanel; |
9 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerPropertiesPanelFactory; |
10 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerPropertiesPanelManager; |
11 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
12 |
import org.gvsig.tools.ToolsLocator; |
13 |
import org.gvsig.tools.dynobject.DynObject; |
14 |
import org.gvsig.tools.i18n.I18nManager; |
15 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
16 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
17 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
18 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
19 |
import org.slf4j.Logger; |
20 |
import org.slf4j.LoggerFactory; |
21 |
|
22 |
|
23 |
public class DefaultFilesystemExplorerPropertiesPanelManager implements FilesystemExplorerPropertiesPanelManager { |
24 |
|
25 |
private static Logger logger = LoggerFactory.getLogger(DefaultFilesystemExplorerPropertiesPanelManager.class); |
26 |
|
27 |
private List<FilesystemExplorerPropertiesPanelFactory> factories = null; |
28 |
|
29 |
public DefaultFilesystemExplorerPropertiesPanelManager() {
|
30 |
this.factories = new ArrayList<>(); |
31 |
} |
32 |
|
33 |
@Override
|
34 |
public void registerFactory(FilesystemExplorerPropertiesPanelFactory factory) { |
35 |
if( this.factories.contains(factory) ) { |
36 |
return;
|
37 |
} |
38 |
this.factories.add(factory);
|
39 |
} |
40 |
|
41 |
@Override
|
42 |
public FilesystemExplorerPropertiesPanelFactory getFactory(DynObject parameters) {
|
43 |
FilesystemExplorerPropertiesPanelFactory factory = null;
|
44 |
for (FilesystemExplorerPropertiesPanelFactory currentFactory : factories) {
|
45 |
if( currentFactory.canBeApplied(parameters) ) {
|
46 |
if( factory == null ) { |
47 |
factory = currentFactory; |
48 |
} else if( factory.getPriority() < currentFactory.getPriority() ) { |
49 |
factory = currentFactory; |
50 |
} |
51 |
} |
52 |
} |
53 |
return factory;
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
public FilesystemExplorerPropertiesPanel createPanel(DynObject parameters) {
|
58 |
FilesystemExplorerPropertiesPanelFactory factory = this.getFactory(parameters);
|
59 |
if( factory == null ) { |
60 |
return null; |
61 |
} |
62 |
return factory.create(parameters);
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void showPropertiesDialog(final DynObject parameters) { |
67 |
|
68 |
final FilesystemExplorerPropertiesPanel panel = this.createPanel(parameters); |
69 |
this.showPropertiesDialog(parameters, panel);
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public void showPropertiesDialog(final DynObject parameters, final FilesystemExplorerPropertiesPanel panel) { |
74 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
75 |
|
76 |
String title = parameters.getDynClass().getDescription();
|
77 |
if( !StringUtils.isEmpty(title) ) {
|
78 |
title = parameters.getDynClass().getName(); |
79 |
} |
80 |
|
81 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
82 |
Dialog dialog = winmanager.createDialog(
|
83 |
panel.asJComponent(), |
84 |
title, |
85 |
null,
|
86 |
WindowManager_v2.BUTTONS_APPLY_OK_CANCEL |
87 |
); |
88 |
if( panel instanceof FilesystemExplorerPropertiesDynObjectPanel ) { |
89 |
dialog.setButtons(WindowManager_v2.BUTTONS_OK_CANCEL); |
90 |
} else {
|
91 |
dialog.setButtonLabel( |
92 |
WindowManager_v2.BUTTON_APPLY, |
93 |
i18nManager.getTranslation("Avanzado")
|
94 |
); |
95 |
} |
96 |
dialog.addActionListener(new ActionListener() { |
97 |
@Override
|
98 |
public void actionPerformed(ActionEvent ae) { |
99 |
switch(ae.getID() ) {
|
100 |
case WindowManager_v2.BUTTON_APPLY:
|
101 |
showAdvancedPropertiesDialog(parameters); |
102 |
break;
|
103 |
case WindowManager_v2.BUTTON_OK:
|
104 |
panel.fetchParameters(parameters); |
105 |
break;
|
106 |
case WindowManager_v2.BUTTON_CANCEL:
|
107 |
break;
|
108 |
} |
109 |
} |
110 |
}); |
111 |
dialog.show(WindowManager.MODE.DIALOG); |
112 |
|
113 |
} |
114 |
|
115 |
private void showAdvancedPropertiesDialog(DynObject parameters) { |
116 |
|
117 |
try {
|
118 |
DynObjectEditor editor = new DynObjectEditor(parameters);
|
119 |
editor.editObject(true);
|
120 |
} catch (Throwable th) { |
121 |
logger.warn("Can't show standard properties dialog for this parameters.",th);
|
122 |
} |
123 |
|
124 |
} |
125 |
} |