Statistics
| Revision:

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 / JMoveScriptModel.java @ 1207

History | View | Annotate | Download (1.99 KB)

1
package org.gvsig.scripting.swing.impl.composer;
2

    
3
import java.io.File;
4
import javax.swing.tree.TreePath;
5

    
6
import org.gvsig.scripting.ScriptingFolder;
7
import org.gvsig.scripting.ScriptingManager;
8
import org.gvsig.scripting.ScriptingUnit;
9

    
10
public class JMoveScriptModel {
11

    
12
  public final static int ACTION_CANCEL = 0;
13
  public final static int ACTION_ACCEPT = 1;
14

    
15
  private ScriptingUnit unit;
16
  private File moveTo;
17
  private int action;
18
  private ScriptingManager manager;
19
  private TreePath initialSelectedPath;
20
  private boolean overwrite;
21

    
22
  public JMoveScriptModel(ScriptingManager manager, ScriptingUnit unit) {
23
    this.manager = manager;
24
    this.unit = unit;
25
    this.overwrite = false;
26
  }
27

    
28
  public boolean isOverwrite() {
29
    return this.overwrite;
30
  }
31
  
32
  public void setOverwrite(boolean overwrite) {
33
    this.overwrite = overwrite;
34
  }
35
  
36
  public void validate() throws Exception {
37
    File file = this.getMoveTo();
38
    if (file == null) {
39
      throw new Exception("Destination must not be empty.");
40
    }
41

    
42
    if (file.exists() ) {
43
      if ( !this.overwrite ) {
44
        throw new Exception("A file existst in the destination folder.");
45
      }
46
      if ( !file.canWrite()) {
47
        throw new Exception("Can't write in the destination folder.");
48
      }
49
    }
50

    
51
    ScriptingFolder folder = manager.getFolder(file);
52
    if (!manager.validateUnitId(folder, this.getUnit().getId())) {
53
      throw new Exception("This file already exists.\nWrite another name for the script");
54
    }
55
  }
56

    
57
  public void setAction(int action) {
58
    this.action = action;
59
  }
60

    
61
  public int getAction() {
62
    return action;
63
  }
64

    
65
  public void setMoveTo(File moveTo) {
66
    this.moveTo = moveTo;
67
  }
68

    
69
  public void setMoveTo(String moveTo) {
70
    this.moveTo = new File(moveTo);
71
  }
72

    
73
  public File getMoveTo() {
74
    return moveTo;
75
  }
76

    
77
  public ScriptingUnit getUnit() {
78
    return unit;
79
  }
80

    
81
  void setSelectionPath(TreePath path) {
82
    this.initialSelectedPath = path;
83
  }
84

    
85
  TreePath getSelectionPath() {
86
    return this.initialSelectedPath;
87
  }
88
}