gvsig-scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.api / src / main / java / org / gvsig / scripting / swing / composer / JRenameScript.java @ 123
History | View | Annotate | Download (3.7 KB)
1 |
package org.gvsig.scripting.swing.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.JLabel; |
10 |
import javax.swing.JOptionPane; |
11 |
import javax.swing.JPanel; |
12 |
import javax.swing.JTextField; |
13 |
import javax.swing.border.TitledBorder; |
14 |
|
15 |
import org.gvsig.scripting.ScriptingManager; |
16 |
import org.gvsig.scripting.ScriptingScript; |
17 |
import org.gvsig.scripting.ScriptingUIManager; |
18 |
import org.gvsig.scripting.ScriptingUnit; |
19 |
import org.gvsig.scripting.swing.AbstractJDialogPanel; |
20 |
|
21 |
public class JRenameScript extends AbstractJDialogPanel{ |
22 |
private ScriptingUIManager uimanager;
|
23 |
private ScriptingManager manager;
|
24 |
private JScriptingComposer composer;
|
25 |
private ScriptingUnit unit;
|
26 |
|
27 |
JTextField oldName = null; |
28 |
JTextField newName =null; |
29 |
JPropertiesScript jProperties = null;
|
30 |
|
31 |
public JRenameScript(ScriptingUIManager uimanager, JScriptingComposer composer, ScriptingUnit unit){
|
32 |
this.uimanager = uimanager;
|
33 |
this.manager = this.uimanager.getManager(); |
34 |
this.composer = composer;
|
35 |
this.unit = unit;
|
36 |
|
37 |
setLayout(new BorderLayout()); |
38 |
|
39 |
JPanel panel = new JPanel(); |
40 |
panel.setLayout(new GridBagLayout()); |
41 |
GridBagConstraints gbc = new GridBagConstraints(); |
42 |
|
43 |
gbc.insets = new Insets(25,10,0,5); |
44 |
gbc.weightx = 0.5;
|
45 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
46 |
gbc.gridx = 0;
|
47 |
gbc.gridy = 0;
|
48 |
panel.add(new JLabel("Current filename: "),gbc); |
49 |
gbc.gridx = 1;
|
50 |
oldName = new JTextField(20); |
51 |
oldName.setText(unit.getId()); |
52 |
oldName.setEditable(false);
|
53 |
panel.add(oldName, gbc); |
54 |
|
55 |
gbc.insets = new Insets(10,10,25,5); |
56 |
gbc.gridx = 0;
|
57 |
gbc.gridy = 1;
|
58 |
panel.add(new JLabel("New filename: "),gbc); |
59 |
gbc.gridx = 1;
|
60 |
newName = new JTextField(20); |
61 |
newName.setText(unit.getId()); |
62 |
panel.add(newName, gbc); |
63 |
|
64 |
TitledBorder title;
|
65 |
title = BorderFactory.createTitledBorder("Change the script's filename"); |
66 |
panel.setBorder(title); |
67 |
|
68 |
jProperties = new JPropertiesScript(this.unit); |
69 |
TitledBorder title2;
|
70 |
title2 = BorderFactory.createTitledBorder("Other script's properties"); |
71 |
jProperties.setBorder(title2); |
72 |
|
73 |
add(panel,BorderLayout.NORTH);
|
74 |
add(jProperties,BorderLayout.CENTER);
|
75 |
} |
76 |
|
77 |
public void actionAccept() { |
78 |
boolean success = true; |
79 |
if (!newName.getText().equals("") && !newName.getText().equals(oldName.getText())){ |
80 |
if(unit.rename(newName.getText())){
|
81 |
JOptionPane.showMessageDialog(null, "Rename succesfully", "Info", JOptionPane.INFORMATION_MESSAGE); |
82 |
composer.launcherRefresh(); |
83 |
unit.setName(jProperties.name.getText()); |
84 |
unit.setDescription(jProperties.description.getText()); |
85 |
unit.setCreatedBy(jProperties.createdBy.getText()); |
86 |
unit.setVersion(jProperties.version.getText()); |
87 |
if(unit instanceof ScriptingScript){ |
88 |
((ScriptingScript)unit).save(); |
89 |
} |
90 |
}else{
|
91 |
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); |
92 |
success = false;
|
93 |
} |
94 |
} |
95 |
if(success)
|
96 |
setVisible(false);
|
97 |
} |
98 |
|
99 |
public void actionApply() { |
100 |
} |
101 |
|
102 |
public void actionCancel() { |
103 |
setVisible(false);
|
104 |
} |
105 |
|
106 |
public boolean isVisibleAccept() { |
107 |
return true; |
108 |
} |
109 |
|
110 |
public boolean isVisibleApply() { |
111 |
return false; |
112 |
} |
113 |
|
114 |
public boolean isVisibleCancel() { |
115 |
return true; |
116 |
} |
117 |
|
118 |
/*public void actionPerformed(ActionEvent arg0) {
|
119 |
JViewport jView = (JViewport)arg0.getSource();
|
120 |
JScrollPane jScroll = (JScrollPane)jView.getParent();
|
121 |
JScriptingBrowser jBrowser = (JScriptingBrowser)jScroll.getParent();
|
122 |
if(jBrowser.getSelectedNode() instanceof ScriptingFolder){
|
123 |
ScriptingFolder selectedFolder = (ScriptingFolder)jBrowser.getSelectedNode();
|
124 |
moveTo.setText(selectedFolder.getPath());
|
125 |
}
|
126 |
}*/
|
127 |
|
128 |
} |