Revision 724
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.swing/org.gvsig.topology.swing.impl/src/main/java/org/gvsig/topology/swing/impl/SelectDataSetDialog.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 | 1 |
package org.gvsig.topology.swing.impl; |
7 | 2 |
|
8 | 3 |
import java.awt.Dimension; |
4 |
import javax.swing.JTree; |
|
9 | 5 |
import javax.swing.event.TreeSelectionEvent; |
10 | 6 |
import javax.swing.event.TreeSelectionListener; |
11 | 7 |
import javax.swing.tree.TreePath; |
... | ... | |
26 | 22 |
|
27 | 23 |
private final TopologySwingServices services; |
28 | 24 |
private Dialog dialog = null; |
29 |
|
|
25 |
|
|
30 | 26 |
SelectDataSetDialog() { |
31 | 27 |
this.services = TopologySwingLocator.getTopologySwingManager().getDefaultServices(); |
32 | 28 |
this.initComponents(); |
33 | 29 |
} |
34 |
|
|
30 |
|
|
35 | 31 |
private void initComponents() { |
36 | 32 |
this.treeDataSets.setModel(this.services.getDataSetTreeModel()); |
33 |
this.expandAll(this.treeDataSets); |
|
37 | 34 |
this.treeDataSets.addTreeSelectionListener(new TreeSelectionListener() { |
38 | 35 |
@Override |
39 | 36 |
public void valueChanged(TreeSelectionEvent e) { |
40 | 37 |
performDataSetSelected(); |
41 | 38 |
} |
42 | 39 |
}); |
43 |
this.setPreferredSize(new Dimension(350, 400));
|
|
40 |
this.setPreferredSize(new Dimension(350, 400)); |
|
44 | 41 |
this.translate(); |
45 | 42 |
} |
46 | 43 |
|
44 |
private void expandAll(JTree tree) { |
|
45 |
int r = 0; |
|
46 |
while (r < tree.getRowCount()) { |
|
47 |
tree.expandRow(r); |
|
48 |
r++; |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
47 | 52 |
private void translate() { |
48 | 53 |
ToolsSwingManager tsm = ToolsSwingLocator.getToolsSwingManager(); |
49 |
tsm.translate(this.lblName);
|
|
54 |
tsm.translate(this.lblName); |
|
50 | 55 |
} |
51 |
|
|
56 |
|
|
52 | 57 |
public void setDialog(Dialog dialog) { |
53 | 58 |
this.dialog = dialog; |
54 | 59 |
} |
55 |
|
|
60 |
|
|
56 | 61 |
private void setOkButtonEnabled(boolean enabled) { |
57 |
if( this.dialog==null ) {
|
|
62 |
if (this.dialog == null) {
|
|
58 | 63 |
return; |
59 | 64 |
} |
60 | 65 |
this.dialog.setButtonEnabled(WindowManager_v2.BUTTONS_OK, enabled); |
61 | 66 |
} |
62 |
|
|
67 |
|
|
63 | 68 |
private TopologyDataSet getSelectedDataSet() { |
64 | 69 |
TreePath path = treeDataSets.getSelectionPath(); |
65 | 70 |
Object element = path.getLastPathComponent(); |
66 |
if( element instanceof TopologyDataSet ) {
|
|
71 |
if (element instanceof TopologyDataSet) {
|
|
67 | 72 |
TopologyDataSet dataSet = (TopologyDataSet) element; |
68 | 73 |
return dataSet; |
69 | 74 |
} |
70 | 75 |
return null; |
71 | 76 |
} |
72 |
|
|
77 |
|
|
73 | 78 |
public TopologyDataSet getDataSet() { |
74 | 79 |
TopologyDataSet dataSet = this.getSelectedDataSet(); |
75 |
if( dataSet == null ) {
|
|
80 |
if (dataSet == null) {
|
|
76 | 81 |
return null; |
77 | 82 |
} |
78 | 83 |
String name = this.txtName.getText(); |
79 |
if( !StringUtils.isEmpty(name) ) {
|
|
84 |
if (!StringUtils.isEmpty(name)) {
|
|
80 | 85 |
dataSet.setName(name); |
81 | 86 |
} |
82 | 87 |
return dataSet; |
83 |
}
|
|
88 |
}
|
|
84 | 89 |
|
85 | 90 |
public void performDataSetSelected() { |
86 | 91 |
TopologyDataSet dataSet = this.getSelectedDataSet(); |
87 |
if( dataSet==null ) {
|
|
92 |
if (dataSet == null) {
|
|
88 | 93 |
this.txtName.setText(""); |
89 | 94 |
this.setOkButtonEnabled(false); |
90 | 95 |
} else { |
... | ... | |
92 | 97 |
this.setOkButtonEnabled(true); |
93 | 98 |
} |
94 | 99 |
} |
95 |
|
|
100 |
|
|
96 | 101 |
} |
Also available in: Unified diff