gvsig-projects-pool / 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 @ 724
History | View | Annotate | Download (3.03 KB)
1 |
package org.gvsig.topology.swing.impl; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import javax.swing.JTree; |
5 |
import javax.swing.event.TreeSelectionEvent; |
6 |
import javax.swing.event.TreeSelectionListener; |
7 |
import javax.swing.tree.TreePath; |
8 |
import org.apache.commons.lang3.StringUtils; |
9 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
10 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
11 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
12 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
13 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
14 |
import org.gvsig.topology.swing.api.TopologySwingLocator; |
15 |
import org.gvsig.topology.swing.api.TopologySwingServices; |
16 |
|
17 |
/**
|
18 |
*
|
19 |
* @author jjdelcerro
|
20 |
*/
|
21 |
public class SelectDataSetDialog extends SelectDataSetDialogView { |
22 |
|
23 |
private final TopologySwingServices services; |
24 |
private Dialog dialog = null; |
25 |
|
26 |
SelectDataSetDialog() { |
27 |
this.services = TopologySwingLocator.getTopologySwingManager().getDefaultServices();
|
28 |
this.initComponents();
|
29 |
} |
30 |
|
31 |
private void initComponents() { |
32 |
this.treeDataSets.setModel(this.services.getDataSetTreeModel()); |
33 |
this.expandAll(this.treeDataSets); |
34 |
this.treeDataSets.addTreeSelectionListener(new TreeSelectionListener() { |
35 |
@Override
|
36 |
public void valueChanged(TreeSelectionEvent e) { |
37 |
performDataSetSelected(); |
38 |
} |
39 |
}); |
40 |
this.setPreferredSize(new Dimension(350, 400)); |
41 |
this.translate();
|
42 |
} |
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 |
|
52 |
private void translate() { |
53 |
ToolsSwingManager tsm = ToolsSwingLocator.getToolsSwingManager(); |
54 |
tsm.translate(this.lblName);
|
55 |
} |
56 |
|
57 |
public void setDialog(Dialog dialog) { |
58 |
this.dialog = dialog;
|
59 |
} |
60 |
|
61 |
private void setOkButtonEnabled(boolean enabled) { |
62 |
if (this.dialog == null) { |
63 |
return;
|
64 |
} |
65 |
this.dialog.setButtonEnabled(WindowManager_v2.BUTTONS_OK, enabled);
|
66 |
} |
67 |
|
68 |
private TopologyDataSet getSelectedDataSet() {
|
69 |
TreePath path = treeDataSets.getSelectionPath();
|
70 |
Object element = path.getLastPathComponent();
|
71 |
if (element instanceof TopologyDataSet) { |
72 |
TopologyDataSet dataSet = (TopologyDataSet) element; |
73 |
return dataSet;
|
74 |
} |
75 |
return null; |
76 |
} |
77 |
|
78 |
public TopologyDataSet getDataSet() {
|
79 |
TopologyDataSet dataSet = this.getSelectedDataSet();
|
80 |
if (dataSet == null) { |
81 |
return null; |
82 |
} |
83 |
String name = this.txtName.getText(); |
84 |
if (!StringUtils.isEmpty(name)) {
|
85 |
dataSet.setName(name); |
86 |
} |
87 |
return dataSet;
|
88 |
} |
89 |
|
90 |
public void performDataSetSelected() { |
91 |
TopologyDataSet dataSet = this.getSelectedDataSet();
|
92 |
if (dataSet == null) { |
93 |
this.txtName.setText(""); |
94 |
this.setOkButtonEnabled(false); |
95 |
} else {
|
96 |
this.txtName.setText(dataSet.getName());
|
97 |
this.setOkButtonEnabled(true); |
98 |
} |
99 |
} |
100 |
|
101 |
} |