svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / databaseworkspace / RepositoryAddTablePanel.java @ 44304
History | View | Annotate | Download (4.79 KB)
1 |
package org.gvsig.geodb.databaseworkspace; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
import javax.swing.DefaultListModel; |
5 |
import javax.swing.JComponent; |
6 |
import javax.swing.event.ListSelectionEvent; |
7 |
import javax.swing.event.ListSelectionListener; |
8 |
import javax.swing.event.TreeSelectionEvent; |
9 |
import javax.swing.event.TreeSelectionListener; |
10 |
import javax.swing.tree.TreeModel; |
11 |
import javax.swing.tree.TreePath; |
12 |
import org.apache.commons.lang3.StringUtils; |
13 |
import org.gvsig.app.ApplicationLocator; |
14 |
import org.gvsig.app.ApplicationManager; |
15 |
import org.gvsig.app.project.Project; |
16 |
import org.gvsig.app.project.documents.Document; |
17 |
import org.gvsig.app.project.documents.table.TableDocument; |
18 |
import org.gvsig.app.project.documents.table.TableManager; |
19 |
import org.gvsig.fmap.dal.DataStoreParameters; |
20 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
21 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
22 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
23 |
import org.gvsig.tools.swing.api.Component; |
24 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
25 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
26 |
import org.gvsig.tools.util.LabeledValue; |
27 |
import org.gvsig.tools.util.LabeledValueImpl; |
28 |
|
29 |
/**
|
30 |
*
|
31 |
* @author jjdelcerro
|
32 |
*/
|
33 |
public class RepositoryAddTablePanel |
34 |
extends RepositoryAddTablePanelView
|
35 |
implements Component |
36 |
{ |
37 |
|
38 |
public RepositoryAddTablePanel() {
|
39 |
this.initComponents();
|
40 |
} |
41 |
|
42 |
private void initComponents() { |
43 |
ApplicationManager application = ApplicationLocator.getManager(); |
44 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
45 |
|
46 |
TreeModel layersModel = application.createProjectLayersTreeModel();
|
47 |
this.treeLayers.setModel(layersModel);
|
48 |
this.treeLayers.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { |
49 |
@Override
|
50 |
public void valueChanged(TreeSelectionEvent e) { |
51 |
doUpdateTableName(); |
52 |
} |
53 |
}); |
54 |
|
55 |
Project project = application.getCurrentProject(); |
56 |
final List<Document> docs = project.getDocuments(TableManager.TYPENAME); |
57 |
if( docs!=null ) { |
58 |
DefaultListModel<LabeledValue<FeatureStore>> tablesModel = new DefaultListModel<>(); |
59 |
for (Document doc : docs) { |
60 |
TableDocument table = (TableDocument) doc; |
61 |
tablesModel.addElement( |
62 |
new LabeledValueImpl<>(table.getName(), table.getFeatureStore())
|
63 |
); |
64 |
} |
65 |
this.lstTables.setModel(tablesModel);
|
66 |
this.lstTables.addListSelectionListener(new ListSelectionListener() { |
67 |
@Override
|
68 |
public void valueChanged(ListSelectionEvent e) { |
69 |
if( e.getValueIsAdjusting() ) {
|
70 |
return;
|
71 |
} |
72 |
doUpdateTableName(); |
73 |
} |
74 |
}); |
75 |
|
76 |
toolsSwingManager.addClearButton(this.txtTableName);
|
77 |
toolsSwingManager.setDefaultPopupMenu(this.txtTableName);
|
78 |
} |
79 |
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public JComponent asJComponent() { |
84 |
return this; |
85 |
} |
86 |
|
87 |
private void doUpdateTableName() { |
88 |
switch(this.tabStores.getSelectedIndex()) { |
89 |
case 0: // Layers |
90 |
TreePath selected = this.treeLayers.getSelectionPath(); |
91 |
FLayer layer = (FLayer) selected.getLastPathComponent(); |
92 |
if( layer instanceof SingleLayer ) { |
93 |
this.txtTableName.setText(layer.getName());
|
94 |
} |
95 |
break;
|
96 |
case 1: // Table documents |
97 |
LabeledValue<FeatureStore> item = (LabeledValue<FeatureStore>) this.lstTables.getSelectedValue();
|
98 |
if( item != null ) { |
99 |
this.txtTableName.setText(item.getLabel());
|
100 |
} |
101 |
break;
|
102 |
default:
|
103 |
break;
|
104 |
} |
105 |
} |
106 |
|
107 |
public String getTableName() { |
108 |
return StringUtils.defaultIfBlank(this.txtTableName.getText(),null); |
109 |
} |
110 |
|
111 |
public DataStoreParameters getDataStoreParameters() {
|
112 |
switch(this.tabStores.getSelectedIndex()) { |
113 |
case 0: // Layers |
114 |
TreePath selected = this.treeLayers.getSelectionPath(); |
115 |
FLayer layer = (FLayer) selected.getLastPathComponent(); |
116 |
if( layer instanceof SingleLayer ) { |
117 |
return ((SingleLayer) layer).getDataStore().getParameters();
|
118 |
} |
119 |
return null; |
120 |
case 1: // Table documents |
121 |
LabeledValue<FeatureStore> item = (LabeledValue<FeatureStore>) this.lstTables.getSelectedValue();
|
122 |
if( item == null ) { |
123 |
return null; |
124 |
} |
125 |
return item.getValue().getParameters();
|
126 |
default:
|
127 |
return null; |
128 |
} |
129 |
} |
130 |
} |