Revision 1207 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
JMoveScriptPanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.scripting.swing.impl.composer; |
2 | 2 |
|
3 |
import java.awt.BorderLayout; |
|
3 | 4 |
import java.awt.Dimension; |
4 |
import java.awt.GridBagConstraints; |
|
5 |
import java.awt.GridBagLayout; |
|
6 |
import java.awt.Insets; |
|
7 | 5 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
|
9 | 6 |
import java.io.File; |
7 |
import java.io.IOException; |
|
10 | 8 |
|
11 | 9 |
import javax.swing.JComponent; |
12 |
import javax.swing.JLabel; |
|
13 | 10 |
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 | 11 |
|
19 | 12 |
import org.gvsig.scripting.ScriptingFolder; |
20 | 13 |
import org.gvsig.scripting.ScriptingManager; |
... | ... | |
24 | 17 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
25 | 18 |
import org.gvsig.scripting.swing.impl.DialogPanel; |
26 | 19 |
|
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(); |
|
20 |
public class JMoveScriptPanel extends JMoveScriptPanelView implements DialogPanel { |
|
51 | 21 |
|
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 |
} |
|
22 |
/** |
|
23 |
* |
|
24 |
*/ |
|
25 |
private static final long serialVersionUID = 1L; |
|
83 | 26 |
|
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 |
} |
|
27 |
private final ScriptingUIManager uimanager; |
|
28 |
private final ScriptingManager manager; |
|
29 |
private final ScriptingUnit unit; |
|
30 |
private final JMoveScriptModel model; |
|
31 |
private DefaultJScriptingBrowser jbrowser; |
|
32 |
private File target; |
|
125 | 33 |
|
126 |
public void actionApply() { |
|
127 |
} |
|
34 |
public JMoveScriptPanel(ScriptingUIManager uimanager, JMoveScriptModel model) { |
|
35 |
this.uimanager = uimanager; |
|
36 |
this.manager = this.uimanager.getManager(); |
|
37 |
this.model = model; |
|
38 |
this.unit = model.getUnit(); |
|
128 | 39 |
|
129 |
public void actionCancel() {
|
|
130 |
setVisible(false);
|
|
131 |
}
|
|
40 |
model.setAction(JNewScriptModel.ACTION_CANCEL);
|
|
41 |
initComponents();
|
|
42 |
}
|
|
132 | 43 |
|
133 |
public boolean isVisibleAccept() { |
|
134 |
return true; |
|
135 |
} |
|
44 |
private void initComponents() { |
|
45 |
this.target = this.unit.getFile(); |
|
136 | 46 |
|
137 |
public boolean isVisibleApply() { |
|
138 |
return false; |
|
139 |
} |
|
47 |
this.txtSource.setText(this.unit.getUserPath()); |
|
48 |
this.txtTarget.setText(this.unit.getUserPath()); |
|
49 |
|
|
50 |
initBrowser(); |
|
51 |
|
|
52 |
this.setPreferredSize(new Dimension(500, 500)); |
|
53 |
this.chkOverwrite.setSelected(this.model.isOverwrite()); |
|
54 |
} |
|
140 | 55 |
|
141 |
public boolean isVisibleCancel() { |
|
142 |
return true; |
|
143 |
} |
|
56 |
private void initBrowser() { |
|
57 |
this.jbrowser = new DefaultJScriptingBrowser(this.uimanager, this.manager.getUserFolder(), true); |
|
58 |
this.jbrowser.setPreferredSize(new Dimension(250, 100)); |
|
59 |
this.pnlBrowserContainer.setLayout(new BorderLayout()); |
|
60 |
this.pnlBrowserContainer.add(jbrowser, BorderLayout.CENTER); |
|
61 |
jbrowser.addActionListener((ActionEvent arg0) -> { |
|
62 |
if (arg0.getID() == JScriptingBrowser.SELECTION_ACTION) { |
|
63 |
doFolderSelection(); |
|
64 |
} |
|
65 |
}); |
|
66 |
jbrowser.setSelectionPath(this.model.getSelectionPath().getParentPath()); |
|
144 | 67 |
|
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 |
|
|
68 |
} |
|
69 |
|
|
70 |
private void doFolderSelection() { |
|
71 |
ScriptingUnit node = jbrowser.getSelectedNode(); |
|
72 |
if (node instanceof ScriptingFolder) { |
|
73 |
ScriptingFolder selectedFolder = (ScriptingFolder) node; |
|
74 |
this.target = new File(selectedFolder.getFile(),this.unit.getFile().getName()); |
|
75 |
this.txtTarget.setText(selectedFolder.getUserPath()+"/"+this.unit.getName()); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public void actionAccept() { |
|
81 |
try { |
|
82 |
if( this.target.getCanonicalFile().equals(this.unit.getFile().getCanonicalFile()) ) { |
|
83 |
JOptionPane.showMessageDialog( |
|
84 |
this, |
|
85 |
"Source and target cannot be the same", |
|
86 |
"Info", |
|
87 |
JOptionPane.INFORMATION_MESSAGE |
|
88 |
); |
|
89 |
return; |
|
90 |
} |
|
91 |
} catch (IOException ex) { |
|
92 |
JOptionPane.showMessageDialog( |
|
93 |
this, |
|
94 |
ex.getMessage(), |
|
95 |
"Info", |
|
96 |
JOptionPane.ERROR_MESSAGE |
|
97 |
); |
|
98 |
return; |
|
99 |
} |
|
100 |
model.setOverwrite(this.chkOverwrite.isSelected()); |
|
101 |
model.setMoveTo(this.target); |
|
102 |
try { |
|
103 |
model.validate(); |
|
104 |
} catch (Exception e) { |
|
105 |
JOptionPane.showMessageDialog( |
|
106 |
this, |
|
107 |
e.getMessage(), |
|
108 |
"Info", |
|
109 |
JOptionPane.WARNING_MESSAGE |
|
110 |
); |
|
111 |
return; |
|
112 |
} |
|
113 |
model.setAction(JNewScriptModel.ACTION_ACCEPT); |
|
114 |
setVisible(false); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public void actionApply() { |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public void actionCancel() { |
|
123 |
setVisible(false); |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public boolean isVisibleAccept() { |
|
128 |
return true; |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public boolean isVisibleApply() { |
|
133 |
return false; |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
public boolean isVisibleCancel() { |
|
138 |
return true; |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
public JComponent getJComponent() { |
|
143 |
return this; |
|
144 |
} |
|
145 |
|
|
160 | 146 |
} |
Also available in: Unified diff