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