gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / JRenamePanel.java @ 457
History | View | Annotate | Download (4.06 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.awt.Insets; |
7 |
|
8 |
import javax.swing.BorderFactory; |
9 |
import javax.swing.JComponent; |
10 |
import javax.swing.JLabel; |
11 |
import javax.swing.JOptionPane; |
12 |
import javax.swing.JPanel; |
13 |
import javax.swing.JTextField; |
14 |
import javax.swing.border.TitledBorder; |
15 |
|
16 |
import org.gvsig.scripting.ScriptingUnit; |
17 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
18 |
import org.gvsig.scripting.swing.impl.DialogPanel; |
19 |
|
20 |
public class JRenamePanel extends JPanel implements DialogPanel { |
21 |
/**
|
22 |
*
|
23 |
*/
|
24 |
private static final long serialVersionUID = 1L; |
25 |
private ScriptingUIManager uimanager;
|
26 |
//private ScriptingManager manager;
|
27 |
private JRenameModel model;
|
28 |
private ScriptingUnit unit;
|
29 |
|
30 |
JTextField oldName = null; |
31 |
JTextField newName =null; |
32 |
JPropertiesScript jProperties = null;
|
33 |
|
34 |
public JRenamePanel(ScriptingUIManager uimanager, JRenameModel model){
|
35 |
this.uimanager = uimanager;
|
36 |
//this.manager = this.uimanager.getManager();
|
37 |
this.model= model;
|
38 |
this.unit = model.getUnit();
|
39 |
|
40 |
model.setAction(JNewScriptModel.ACTION_CANCEL); |
41 |
|
42 |
setLayout(new BorderLayout()); |
43 |
|
44 |
JPanel panel = new JPanel(); |
45 |
panel.setLayout(new GridBagLayout()); |
46 |
GridBagConstraints gbc = new GridBagConstraints(); |
47 |
|
48 |
gbc.insets = new Insets(25,10,0,5); |
49 |
gbc.weightx = 0.5;
|
50 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
51 |
gbc.gridx = 0;
|
52 |
gbc.gridy = 0;
|
53 |
panel.add(new JLabel(this.uimanager.getTranslation("current_name")+": "),gbc); |
54 |
gbc.gridx = 1;
|
55 |
oldName = new JTextField(20); |
56 |
oldName.setText(unit.getId()); |
57 |
oldName.setEditable(false);
|
58 |
panel.add(oldName, gbc); |
59 |
|
60 |
gbc.insets = new Insets(10,10,25,5); |
61 |
gbc.gridx = 0;
|
62 |
gbc.gridy = 1;
|
63 |
panel.add(new JLabel(this.uimanager.getTranslation("new_name")+": "),gbc); |
64 |
gbc.gridx = 1;
|
65 |
newName = new JTextField(20); |
66 |
newName.setText(unit.getId()); |
67 |
panel.add(newName, gbc); |
68 |
|
69 |
TitledBorder title;
|
70 |
title = BorderFactory.createTitledBorder(this.uimanager.getTranslation("rename_name_title")); |
71 |
panel.setBorder(title); |
72 |
|
73 |
jProperties = new JPropertiesScript(this.unit, false); |
74 |
TitledBorder title2;
|
75 |
title2 = BorderFactory.createTitledBorder(this.uimanager.getTranslation("more_properties")); |
76 |
jProperties.setBorder(title2); |
77 |
|
78 |
add(panel,BorderLayout.NORTH);
|
79 |
add(jProperties,BorderLayout.CENTER);
|
80 |
} |
81 |
|
82 |
public void actionAccept() { |
83 |
model.setNewName(newName.getText().trim()); |
84 |
unit.setName(jProperties.name.getText().trim()); |
85 |
unit.setDescription(jProperties.description.getText().trim()); |
86 |
unit.setCreatedBy(jProperties.createdBy.getText().trim()); |
87 |
unit.setVersion(jProperties.version.getText().trim()); |
88 |
model.setUnit(this.unit);
|
89 |
|
90 |
try {
|
91 |
model.validate(); |
92 |
} catch (Exception e) { |
93 |
JOptionPane.showMessageDialog(null, e.getMessage(), "Info", JOptionPane.INFORMATION_MESSAGE); |
94 |
return;
|
95 |
} |
96 |
|
97 |
model.setAction(JRenameModel.ACTION_ACCEPT); |
98 |
setVisible(false);
|
99 |
|
100 |
// boolean success = true;
|
101 |
// if (!newName.getText().equals("") && !newName.getText().equals(oldName.getText())){
|
102 |
// if(unit.rename(newName.getText())){
|
103 |
// JOptionPane.showMessageDialog(null, "Rename succesfully", "Info", JOptionPane.INFORMATION_MESSAGE);
|
104 |
// composer.launcherRefresh();
|
105 |
// }else{
|
106 |
// JOptionPane.showMessageDialog(null, "There're another file with the same name on the final directory\nRename the file or select another destiny.", "Error", JOptionPane.ERROR_MESSAGE);
|
107 |
// success = false;
|
108 |
// }
|
109 |
// }
|
110 |
// unit.setName(jProperties.name.getText());
|
111 |
// unit.setDescription(jProperties.description.getText());
|
112 |
// unit.setCreatedBy(jProperties.createdBy.getText());
|
113 |
// unit.setVersion(jProperties.version.getText());
|
114 |
// if(unit instanceof ScriptingScript){
|
115 |
// ((ScriptingScript)unit).save();
|
116 |
// }
|
117 |
// if(success)
|
118 |
// setVisible(false);
|
119 |
} |
120 |
|
121 |
public void actionApply() { |
122 |
} |
123 |
|
124 |
public void actionCancel() { |
125 |
setVisible(false);
|
126 |
} |
127 |
|
128 |
public boolean isVisibleAccept() { |
129 |
return true; |
130 |
} |
131 |
|
132 |
public boolean isVisibleApply() { |
133 |
return false; |
134 |
} |
135 |
|
136 |
public boolean isVisibleCancel() { |
137 |
return true; |
138 |
} |
139 |
public JComponent getJComponent() { |
140 |
return this; |
141 |
} |
142 |
|
143 |
} |