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 / JMoveScriptPanel.java @ 457
History | View | Annotate | Download (4.77 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.awt.Insets; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.io.File; |
10 |
|
11 |
import javax.swing.JComponent; |
12 |
import javax.swing.JLabel; |
13 |
import javax.swing.JOptionPane; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.JScrollPane; |
16 |
import javax.swing.JTextField; |
17 |
import javax.swing.JViewport; |
18 |
|
19 |
import org.gvsig.scripting.ScriptingFolder; |
20 |
import org.gvsig.scripting.ScriptingManager; |
21 |
import org.gvsig.scripting.ScriptingUnit; |
22 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
23 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
24 |
import org.gvsig.scripting.swing.impl.DialogPanel; |
25 |
|
26 |
public class JMoveScriptPanel extends JPanel implements DialogPanel, ActionListener{ |
27 |
/**
|
28 |
*
|
29 |
*/
|
30 |
private static final long serialVersionUID = 1L; |
31 |
private ScriptingUIManager uimanager;
|
32 |
private ScriptingManager manager;
|
33 |
//private DefaultJScriptingComposer composer;
|
34 |
private ScriptingUnit unit;
|
35 |
private JMoveScriptModel model;
|
36 |
|
37 |
JTextField from = null; |
38 |
JTextField moveTo =null; |
39 |
|
40 |
public JMoveScriptPanel(ScriptingUIManager uimanager, JMoveScriptModel model){
|
41 |
this.uimanager = uimanager;
|
42 |
this.manager = this.uimanager.getManager(); |
43 |
this.model= model;
|
44 |
this.unit = model.getUnit();
|
45 |
|
46 |
model.setAction(JNewScriptModel.ACTION_CANCEL); |
47 |
|
48 |
setLayout(new GridBagLayout()); |
49 |
GridBagConstraints gbc = new GridBagConstraints(); |
50 |
|
51 |
gbc.insets = new Insets(25,10,0,5); |
52 |
gbc.weightx = 0.5;
|
53 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
54 |
gbc.gridx = 0;
|
55 |
gbc.gridy = 0;
|
56 |
add(new JLabel(this.uimanager.getTranslation("Move_from")+": "),gbc); |
57 |
gbc.gridx = 1;
|
58 |
from = new JTextField(20); |
59 |
from.setText(unit.getParent().getFile().getAbsolutePath()); |
60 |
from.setEditable(false);
|
61 |
add(from, gbc); |
62 |
|
63 |
gbc.gridx = 0;
|
64 |
gbc.gridy = 1;
|
65 |
add(new JLabel(this.uimanager.getTranslation("Move_to")+": "),gbc); |
66 |
gbc.gridx = 1;
|
67 |
moveTo = new JTextField(20); |
68 |
moveTo.setEditable(false);
|
69 |
moveTo.setText(this.manager.getRootUserFolder().getAbsolutePath());
|
70 |
add(moveTo, gbc); |
71 |
|
72 |
gbc.insets = new Insets(10,10,25,5); |
73 |
gbc.gridx = 0;
|
74 |
gbc.gridy = 2;
|
75 |
gbc.gridwidth = 2;
|
76 |
DefaultJScriptingBrowser jbrowser = new DefaultJScriptingBrowser(this.uimanager,this.manager.getUserFolder(),true); |
77 |
jbrowser.setPreferredSize(new Dimension(250,100)); |
78 |
jbrowser.addSelectionActionListener(this);
|
79 |
add(jbrowser,gbc); |
80 |
|
81 |
} |
82 |
|
83 |
public void actionAccept() { |
84 |
model.setMoveTo(new File(moveTo.getText().trim())); |
85 |
|
86 |
// if(model.getMoveTo().length()==0){
|
87 |
// JOptionPane.showMessageDialog(null, "Name must not be empty.", "Error", JOptionPane.ERROR_MESSAGE);
|
88 |
// return;
|
89 |
// }
|
90 |
//
|
91 |
// File file = new File(model.getMoveTo());
|
92 |
// if(!file.exists() || !file.canWrite()){
|
93 |
// JOptionPane.showMessageDialog(null, "Not a valid destination.", "Error", JOptionPane.ERROR_MESSAGE);
|
94 |
// return;
|
95 |
// }
|
96 |
// ScriptingFolder folder = manager.getFolder(file);
|
97 |
// if(!manager.validateUnitId(folder,unit.getId())){
|
98 |
// 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);
|
99 |
// return;
|
100 |
// }
|
101 |
|
102 |
try {
|
103 |
model.validate(); |
104 |
} catch (Exception e) { |
105 |
JOptionPane.showMessageDialog(null, e.getMessage(), "Info", JOptionPane.INFORMATION_MESSAGE); |
106 |
return;
|
107 |
} |
108 |
|
109 |
model.setAction(JNewScriptModel.ACTION_ACCEPT); |
110 |
setVisible(false);
|
111 |
|
112 |
// if(manager.validateUnitId(folder,unit.getId())){
|
113 |
// if (unit.move(folder)){
|
114 |
// JOptionPane.showMessageDialog(null, "File moved succesfully.", "Info", JOptionPane.INFORMATION_MESSAGE);
|
115 |
// setVisible(false);
|
116 |
// composer.launcherRefresh();
|
117 |
// }else{
|
118 |
// JOptionPane.showMessageDialog(null, "Unexpected error moving the file", "Error", JOptionPane.ERROR_MESSAGE);
|
119 |
// }
|
120 |
// }
|
121 |
// else
|
122 |
// 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);
|
123 |
} |
124 |
|
125 |
public void actionApply() { |
126 |
} |
127 |
|
128 |
public void actionCancel() { |
129 |
setVisible(false);
|
130 |
} |
131 |
|
132 |
public boolean isVisibleAccept() { |
133 |
return true; |
134 |
} |
135 |
|
136 |
public boolean isVisibleApply() { |
137 |
return false; |
138 |
} |
139 |
|
140 |
public boolean isVisibleCancel() { |
141 |
return true; |
142 |
} |
143 |
|
144 |
public void actionPerformed(ActionEvent arg0) { |
145 |
JViewport jView = (JViewport)arg0.getSource(); |
146 |
JScrollPane jScroll = (JScrollPane)jView.getParent(); |
147 |
DefaultJScriptingBrowser jBrowser = (DefaultJScriptingBrowser)jScroll.getParent(); |
148 |
if(jBrowser.getSelectedNode() instanceof ScriptingFolder){ |
149 |
ScriptingFolder selectedFolder = (ScriptingFolder)jBrowser.getSelectedNode(); |
150 |
moveTo.setText(selectedFolder.getFile().getAbsolutePath()); |
151 |
} |
152 |
} |
153 |
public JComponent getJComponent() { |
154 |
return this; |
155 |
} |
156 |
|
157 |
} |