svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / preferencespage / databaseworkspace / DatabaseWorkspacePage.java @ 47469
History | View | Annotate | Download (4.4 KB)
1 |
package org.gvsig.app.gui.preferencespage.databaseworkspace; |
---|---|
2 |
|
3 |
import javax.swing.DefaultComboBoxModel; |
4 |
import javax.swing.DefaultListModel; |
5 |
import javax.swing.ImageIcon; |
6 |
import javax.swing.JPanel; |
7 |
import org.gvsig.andami.IconThemeHelper; |
8 |
import org.gvsig.andami.PluginServices; |
9 |
import org.gvsig.andami.PluginsLocator; |
10 |
import org.gvsig.andami.PluginsManager; |
11 |
import org.gvsig.andami.preferences.IPreference; |
12 |
import org.gvsig.andami.preferences.StoreException; |
13 |
import org.gvsig.fmap.dal.DALLocator; |
14 |
import org.gvsig.fmap.dal.DataManager; |
15 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
16 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
17 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
18 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
19 |
import org.gvsig.tools.ToolsLocator; |
20 |
import org.gvsig.tools.dynobject.DynObject; |
21 |
import org.gvsig.tools.i18n.I18nManager; |
22 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
23 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
24 |
|
25 |
|
26 |
@SuppressWarnings("UseSpecificCatch") |
27 |
public class DatabaseWorkspacePage extends DatabaseWorkspacePageView implements IPreference { |
28 |
|
29 |
//
|
30 |
// The class DatabaseWorkspacePage can extend from AbstractPreferencePage, not JPanel,
|
31 |
// if recreate it from the GUI builder change te class declaration to:
|
32 |
// public abstract class DatabaseWorkspacePageView extends AbstractPreferencePage
|
33 |
|
34 |
private final ImageIcon icon; |
35 |
public static String id = DatabaseWorkspacePage.class.getName(); |
36 |
|
37 |
public DatabaseWorkspacePage() {
|
38 |
setParentID("org.gvsig.coreplugin.preferences.general.GeneralPage");
|
39 |
icon = IconThemeHelper.getImageIcon("databaseworkspace-preferences");
|
40 |
initComponents(); |
41 |
} |
42 |
|
43 |
@Override
|
44 |
public boolean isResizeable() { |
45 |
return true; |
46 |
} |
47 |
|
48 |
private void initComponents() { |
49 |
this.translateAll();
|
50 |
} |
51 |
|
52 |
private void translateAll() { |
53 |
ToolsSwingManager manager = ToolsSwingLocator.getToolsSwingManager(); |
54 |
|
55 |
manager.translate(this.lblSelectWorkspace);
|
56 |
manager.translate(this.chkConnectAutomatically);
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void storeValues() throws StoreException { |
61 |
PluginsManager pluginManager = PluginsLocator.getPluginsManager(); |
62 |
PluginServices plugin = pluginManager.getPlugin(this);
|
63 |
DynObject preferences = plugin.getPluginProperties(); |
64 |
|
65 |
preferences.setDynValue("connectAutomaticallyToDatabaseWorkspace", this.chkConnectAutomatically.isSelected()); |
66 |
preferences.setDynValue("databaseWorkspaceToConnect",this.cboSelectWorkspace.getSelectedItem()); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public void setChangesApplied() { |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public String getID() { |
75 |
return id;
|
76 |
} |
77 |
|
78 |
@Override
|
79 |
public String getTitle() { |
80 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
81 |
return i18nManager.getTranslation("_Database_repositories"); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public JPanel getPanel() { |
86 |
return this; |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void initializeValues() { |
91 |
PluginsManager pluginManager = PluginsLocator.getPluginsManager(); |
92 |
DataManager dataManager = DALLocator.getDataManager(); |
93 |
|
94 |
DefaultComboBoxModel<String> connectionsModel = new DefaultComboBoxModel<>(); |
95 |
DataServerExplorerPool connections = dataManager.getDataServerExplorerPool(); |
96 |
for (DataServerExplorerPoolEntry connectionEntry : connections) {
|
97 |
DataServerExplorerParameters connection = connectionEntry.getExplorerParameters(); |
98 |
DatabaseWorkspaceManager workspaceManager = dataManager.createDatabaseWorkspaceManager(connection); |
99 |
if( workspaceManager.isValid() ) {
|
100 |
connectionsModel.addElement(connectionEntry.getName()); |
101 |
} |
102 |
} |
103 |
this.cboSelectWorkspace.setModel(connectionsModel);
|
104 |
|
105 |
PluginServices plugin = pluginManager.getPlugin(this);
|
106 |
DynObject preferences = plugin.getPluginProperties(); |
107 |
this.cboSelectWorkspace.setSelectedIndex(-1); |
108 |
this.chkConnectAutomatically.setSelected((Boolean)(preferences.getDynValue("connectAutomaticallyToDatabaseWorkspace"))); |
109 |
this.cboSelectWorkspace.setSelectedItem(preferences.getDynValue("databaseWorkspaceToConnect")); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void initializeDefaults() { |
114 |
this.initializeValues();
|
115 |
this.chkConnectAutomatically.setSelected(false); |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public ImageIcon getIcon() { |
120 |
return this.icon; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public boolean isValueChanged() { |
125 |
return true; |
126 |
} |
127 |
|
128 |
} |