Revision 301 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingDialog.java

View differences:

DefaultScriptingDialog.java
4 4
import java.awt.event.ActionListener;
5 5
import java.io.File;
6 6

  
7
import javax.script.ScriptEngine;
8

  
9 7
import org.gvsig.scripting.ScriptingDialog;
10 8
import org.gvsig.scripting.ScriptingManager;
11 9
import org.gvsig.scripting.swing.api.JThinlet;
......
19 17

  
20 18
	public DefaultScriptingDialog(ScriptingManager manager) {
21 19
		super(manager);
22
		this.showMode=MODE_DIALOG;
20
		this.setMainName("onload");
21
		this.showMode=MODE_WINDOW;
23 22
	}
24 23
	
25 24
	
......
29 28
		JThinlet thinlet = uimanager.createJThinlet();
30 29
		thinlet.addActionListener(this);
31 30
		thinlet.load(this.getFileResource(".dlg"));
31

  
32
		this.put("dialog", thinlet.getThinlet());
32 33
		
33
		ScriptEngine scriptEngine = (ScriptEngine)this.getEngine();
34
		scriptEngine.put("dialog", thinlet.getThinlet());
35
		
34
		this.compile();
35
		this.invokeFunction(this.getMainName(), args);		
36

  
36 37
		switch(this.getShowMode()){
37 38
		case MODE_WINDOW:
38 39
			uimanager.showWindow(thinlet, this.getName());
......
44 45
			uimanager.showDialog(thinlet, this.getName());
45 46
			break;
46 47
		}
47
		uimanager.showDialog(thinlet, this.getName());
48 48
		return null;
49 49
	}
50 50
	
51 51
	protected void loadInf(Ini prefs){
52 52
		super.loadInf(prefs);
53
		this.showMode=Integer.parseInt(getInfValue(prefs,"Dialog","showMode",new Integer(MODE_DIALOG)).toString());
53
		this.showMode=Integer.parseInt(getInfValue(prefs,"Dialog","showMode",new Integer(MODE_WINDOW)).toString());
54 54
	}
55 55

  
56 56
	protected void save(Ini prefs){
......
66 66
	public void actionPerformed(ActionEvent arg0) {
67 67
		try {
68 68
			this.invokeFunction(arg0.getActionCommand(),null);
69
		} catch (NoSuchMethodException e) {
70
			throw new RuntimeException(e);
69
		} catch (Throwable e) {
70
			// Ignore, invokeFunction handle error it self.
71 71
		}
72 72
	}
73 73

  
......
75 75
		return this.getFileResource(".dlg");
76 76
	}
77 77
	
78
//	public void save(){
79
//		File f = getFileResource(".inf");
80
//		if(!f.isFile()){
81
//			try {
82
//				f.createNewFile();
83
//			} catch (IOException e) {
84
//				e.printStackTrace();
85
//			}
86
//		}
87
//
88
//		Ini prefs = null;
89
//
90
//		try {
91
//			prefs = new Ini(f);
92
//		} catch (InvalidFileFormatException e) {
93
//			e.printStackTrace();
94
//		} catch (IOException e) {
95
//			e.printStackTrace();
96
//		}
97
//
98
//		save(prefs);
99
//
100
//		// Guardo el código en el fichero
101
//		try{
102
//			FileWriter fstream = new FileWriter(((DefaultScriptingFolder)this.getParent()).getPath()+File.separator+this.getId()+this.getExtension());
103
//			BufferedWriter out = new BufferedWriter(fstream);
104
//			out.write(this.getCode());
105
//			out.close();
106
//		}catch (Exception e){
107
//			System.err.println("Error: " + e.getMessage());
108
//		}
109
//	}
110

  
111

  
112 78
	public int getShowMode() {
113 79
		return this.showMode;
114 80
	}

Also available in: Unified diff