Revision 650

View differences:

org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig/libs/formpanel.py
28 28
from org.gvsig.tools import ToolsLocator
29 29
import org.gvsig.tools.swing.api.Component
30 30

  
31
def getResource(*args):
32
  base = args[0]
33
  if os.path.isfile(base):
34
    base = os.path.dirname(base)
35
  x = [ base,]
36
  x.extend(args[1:])
37
  return os.path.join(*x)
38

  
31 39
class ListenerAdapter:
32 40
  def __init__(self,function,componentName=None):
33 41
    self.function = function
......
269 277

  
270 278
  def load(self, formfile):
271 279
    if not isinstance(formfile,java.io.File):
280
      if getattr(formfile,"__getitem__", None)!=None:
281
        formfile = getResource(*formfile)
272 282
      formfile = java.io.File(str(formfile))
273 283
    #print "FormPanel.load(%s)" % formfile
274 284
    self._panel = com.jeta.forms.components.panel.FormPanel( java.io.FileInputStream(formfile) )
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/uselib.py
32 32
  import sys
33 33
  if not folder in sys.path:
34 34
    sys.path.append(folder)
35

  
36
def use_jars(base,folder):
37
  import os.path
38

  
39
  if os.path.isfile(base):
40
    base = os.path.dirname(base)
41
  folder = os.path.join(base,folder)
42
  for f in os.listdir(folder):
43
    if f.endswith(".jar"):
44
      pathname = os.path.join(folder,f)
45
      use_jar(pathname)
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/pom.xml
62 62
            <artifactId>formsrt</artifactId>
63 63
            <scope>compile</scope>
64 64
        </dependency>
65

  
65
        <dependency>
66
            <groupId>org.python</groupId>
67
            <artifactId>${jython.artifactId}</artifactId>
68
            <scope>compile</scope>
69
        </dependency>  
66 70
    </dependencies>
67 71
    <build>
68 72
        <plugins>
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingScript.java
1 1
package org.gvsig.scripting.impl;
2 2

  
3
import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
4
import java.io.BufferedReader;
5 3
import java.io.File;
6 4
import java.io.IOException;
7 5
import java.io.InputStream;
8
import java.io.InputStreamReader;
9 6
import java.util.List;
10 7

  
11 8
import javax.script.Compilable;
......
18 15
import org.apache.commons.io.FilenameUtils;
19 16
import org.apache.commons.io.IOUtils;
20 17
import org.apache.commons.lang3.StringUtils;
18
import org.apache.commons.lang3.exception.ExceptionUtils;
21 19
import org.gvsig.scripting.CompileErrorException;
22 20
import org.gvsig.scripting.ExecuteErrorException;
23 21
import org.gvsig.scripting.Main;
......
31 29
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable;
32 30
import org.gvsig.tools.task.AbstractMonitorableTask;
33 31
import org.ini4j.Ini;
32
import org.python.core.PyException;
33
import org.python.core.PyString;
34
import org.python.core.PyTraceback;
34 35
import org.slf4j.Logger;
35 36
import org.slf4j.LoggerFactory;
36 37

  
......
323 324
                        this.compiledCode.eval();
324 325
                    }
325 326
                } catch (ScriptException e) {
326
                    CompileErrorException ce = new CompileErrorException(e.getMessage(), this.getName(), e.getLineNumber(), e.getColumnNumber(), e);
327
                    Object[] location = this.getLocation(e);
328
                    CompileErrorException ce = new CompileErrorException(
329
                            e.getMessage(), 
330
                            (File) location[0], 
331
                            (int) location[1], 
332
                            (int) location[2], 
333
                            e
334
                    );
327 335
                    notifyErrors(ce, "compile");
328 336
                    throw ce;
329 337
                } catch (Throwable e) {
330
                    CompileErrorException ce = new CompileErrorException(e.getMessage(), this.getName(), e);
338
                    CompileErrorException ce = new CompileErrorException(e.getMessage(), this.getScriptFile(), e);
331 339
                    notifyErrors(new Exception(e), "compile");
332 340
                    throw ce;
333 341
                }
......
336 344
                try {
337 345
                    engine.eval(code);
338 346
                } catch (ScriptException e) {
339
                    CompileErrorException ce = new CompileErrorException(e.getMessage(), this.getName(), e.getLineNumber(), e.getColumnNumber(), e);
347
                    Object[] location = this.getLocation(e);
348
                    CompileErrorException ce = new CompileErrorException(
349
                            e.getMessage(), 
350
                            (File) location[0], 
351
                            (int) location[1], 
352
                            (int) location[2], 
353
                            e
354
                    );                    
340 355
                    notifyErrors(ce, "compile");
341 356
                    throw ce;
342 357
                }
......
406 421
                return null;
407 422
            }
408 423
        } catch (ScriptException e) {
409
            ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getName(), e.getLineNumber(), e.getColumnNumber(), e);
424
            Object[] location = this.getLocation(e);
425
            ExecuteErrorException ee = new ExecuteErrorException(
426
                    e.getMessage(), 
427
                    (File) location[0], 
428
                    (int) location[1], 
429
                    (int) location[2], 
430
                    e
431
            );
410 432
            notifyErrors(ee, "invoke");
411 433
            throw ee;
412 434

  
413 435
        } catch (Error | Exception e) {
414
            ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getName(), e);
436
            ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getScriptFile(), e);
415 437
            notifyErrors(ee, "invoke");
416 438
            throw ee;
417 439
        }
418 440
    }
419 441

  
420 442
    @Override
443
    public File getScriptFile() {
444
        return this.getFileResource(extension);
445
    }
446

  
447
    private Object[] getLocation(ScriptException e) {
448
        Throwable[] es = ExceptionUtils.getThrowables(e);
449
        Exception dbgex; // Para debug con mas comodidad
450
        for( Throwable t : es) {
451
            if( t instanceof PyException ) {
452
                try {
453
                    PyException pyex = (PyException)t;
454
                    PyTraceback tb = pyex.traceback;
455
                    if( tb!=null ) {
456
                        while( tb.tb_next!=null ) {
457
                            tb = (PyTraceback) tb.tb_next;
458
                        }
459
                        String s = tb.tb_frame.f_globals.__getitem__(new PyString("__file__")).asString();
460
                        if( s.endsWith("$py.class") ) {
461
                            s = s.substring(0, s.length()-9) + ".py";
462
                            File resource = new File(s);
463
                            return new Object[] { resource, tb.tb_lineno, 0};
464
                        }
465
                        return new Object[] { this.getScriptFile(), tb.tb_lineno, 0};
466
                    }
467
                } catch(Exception ex) {
468
                    // Pass
469
                    dbgex = ex;
470
                }
471
            }
472
        }        
473
        int column = e.getColumnNumber();
474
        if( column < 0 ) {
475
            column = 0;
476
        }
477
        return new Object[] { this.getScriptFile(), e.getLineNumber(), column };
478
    }
479
    
480
    
481
    @Override
421 482
    public Object invokeMethod(final Object obj, final String name, Object[] args)
422 483
            throws NoSuchMethodException {
423 484

  
......
430 491
            try {
431 492
                return invocable.invokeMethod(obj, name, args);
432 493
            } catch (ScriptException e) {
433
                ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getName(), e.getLineNumber(), e.getColumnNumber(), e);
494
                ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getScriptFile(), e.getLineNumber(), e.getColumnNumber(), e);
434 495
                notifyErrors(ee, "invoke");
435 496
                throw ee;
436 497
            } catch (Throwable e) {
437
                ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getName(), e);
498
                ExecuteErrorException ee = new ExecuteErrorException(e.getMessage(), this.getScriptFile(), e);
438 499
                notifyErrors(ee, "invoke");
439 500
                throw ee;
440 501
            }
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/CompileErrorException.java
1 1
package org.gvsig.scripting;
2 2

  
3
public class CompileErrorException extends RuntimeException {
3
import java.io.File;
4 4

  
5
public class CompileErrorException extends ScriptingErrorException {
6

  
5 7
	/**
6 8
	 * 
7 9
	 */
8 10
	private static final long serialVersionUID = -7829204331513125285L;
9
	private String name;
10
	private int line;
11
	private int column;
12 11

  
13
	public CompileErrorException(String msg, String name, int line, int column) {
14
		super(msg);
15
		this.name = name;
16
		this.line = line;
17
		this.column = column;
12
	public CompileErrorException(String msg, File name, int line, int column) {
13
		super(msg, name, line, column);
18 14
	}
19 15
	
20
	public CompileErrorException(String msg, String name, int line, int column, Throwable cause) {
16
	public CompileErrorException(String msg, File name, int line, int column, Throwable cause) {
21 17
		this(msg, name, line, column);
22 18
		this.initCause(cause);
23 19
	}
24 20
	
25
	public CompileErrorException(String msg, String name, Throwable cause) {
21
	public CompileErrorException(String msg, File name, Throwable cause) {
26 22
		this(msg, name, -1, -1);
27 23
		this.initCause(cause);
28 24
	}
29
	
30
	public int getLineNumber() {
31
		return this.line;
32
	}
33
	
34
	public int 	getColumnNumber() {
35
		return this.column;
36
	}
37
	
38
	public String getScriptName() {
39
		return this.name;
40
	}
41 25
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingBaseScript.java
15 15
 * @see ScriptingProject
16 16
 */
17 17
public interface ScriptingBaseScript extends ScriptingUnit, WeakReferencingObservable {
18
	
18

  
19 19
    /**
20 20
     * Check if the script execution is enabled.
21
     * 
21
     *
22 22
     * @return if the script is enabled.
23 23
     */
24 24
    public boolean isEnabled();
25 25

  
26 26
    /**
27 27
     * Enable or disable the sript execution.
28
     * 
29
     * @param enabled 
28
     *
29
     * @param enabled
30 30
     */
31 31
    public void setEnabled(boolean enabled);
32 32

  
......
78 78
     */
79 79
    public File getResource(String filename);
80 80

  
81
    public File getScriptFile();
81 82
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingScript.java
1 1
package org.gvsig.scripting;
2 2

  
3
import java.io.File;
3 4
import org.gvsig.tools.script.Script;
4 5

  
5 6

  
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ExecuteErrorException.java
1 1
package org.gvsig.scripting;
2 2

  
3
public class ExecuteErrorException extends RuntimeException {
3
import java.io.File;
4 4

  
5
public class ExecuteErrorException extends ScriptingErrorException {
6

  
5 7
	/**
6 8
	 * 
7 9
	 */
8 10
	private static final long serialVersionUID = 3733567933742742587L;
9
	private String name;
10
	private int line;
11
	private int column;
12 11

  
13
	public ExecuteErrorException(String msg, String name, int line, int column) {
14
		super(msg);
15
		this.name = name;
16
		this.line = line;
17
		this.column = column;
12
	public ExecuteErrorException(String msg, File name, int line, int column) {
13
		super(msg, name, line, column);
18 14
	}
19 15
	
20
	public ExecuteErrorException(String msg, String name, int line, int column, Throwable cause) {
16
	public ExecuteErrorException(String msg, File name, int line, int column, Throwable cause) {
21 17
		this(msg, name, line, column);
22 18
		this.initCause(cause);
23 19
	}
24 20
	
25
	public ExecuteErrorException(String msg, String name, Throwable cause) {
21
	public ExecuteErrorException(String msg, File name, Throwable cause) {
26 22
		this(msg, name, -1, -1);
27 23
		this.initCause(cause);
28 24
	}
29 25
	
30
	public int getLineNumber() {
31
		return this.line;
32
	}
33
	
34
	public int 	getColumnNumber() {
35
		return this.column;
36
	}
37
	
38
	public String getScriptName() {
39
		return this.name;
40
	}
41 26
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingErrorException.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.scripting;
7

  
8
import java.io.File;
9
import org.apache.commons.io.FilenameUtils;
10

  
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
public class ScriptingErrorException extends RuntimeException {
16
    private static final long serialVersionUID = -3489829775437358107L;
17
    private final File name;
18
    private final int line;
19
    private final int column;
20

  
21
    public ScriptingErrorException(String msg, File name, int line, int column) {
22
        super(msg);
23
        this.name = name;
24
        this.line = line;
25
        this.column = column;
26
    }
27

  
28
    public int getLineNumber() {
29
        return this.line;
30
    }
31

  
32
    public int getColumnNumber() {
33
        return this.column;
34
    }
35

  
36
    public String getScriptName() {
37
        return FilenameUtils.getBaseName(this.name.getName());
38
    }
39
   
40
    public File getScriptFile() {
41
        return this.name;
42
    }
43
}
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.api/src/main/java/org/gvsig/scripting/swing/api/ScriptingUIManager.java
225 225
    
226 226
    public JScriptingConsole createJScriptingConsole();
227 227
    
228
    public JScriptingConsole createJScriptingConsole(boolean captureOutput);
229
        
228 230
    public void addComposerTool(Action action);
229 231
    
230 232
    public void addComposerMenu(String text, Action action);
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.api/src/main/java/org/gvsig/scripting/swing/api/JScriptingComposer.java
1 1
package org.gvsig.scripting.swing.api;
2 2

  
3 3
import java.awt.event.ActionListener;
4
import java.io.File;
4 5
import javax.swing.JPanel;
5 6
import javax.swing.event.ChangeListener;
6 7
import javax.swing.event.ListSelectionListener;
......
57 58
        public interface Problem {
58 59
            public String getType();
59 60
            public String getMessage();
60
            public String getResource();
61
            public String getResourceName();
62
            public File getResource();
61 63
            public int getLineNumber();
62 64
        }
63 65
        public void addListSelectionListener(ListSelectionListener listener);
......
67 69
        public void removeAll();
68 70
        public void add(String type, String message, String resource, String location);
69 71
        public void add(String type, String message, String resource, int line, int column);
72
        public void add(String type, Exception e) ;
70 73
    }
71 74
        
72 75
    public interface StatusBar extends Component {
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/DefaultScriptingUIManager.java
306 306

  
307 307
    @Override
308 308
    public JScriptingConsole createJScriptingConsole() {
309
        return new DefaultJScriptingConsole();
309
        return new DefaultJScriptingConsole(true);
310 310
    }
311 311

  
312 312
    @Override
313
    public JScriptingConsole createJScriptingConsole(boolean captureOutput) {
314
        return new DefaultJScriptingConsole(captureOutput);
315
    }
316

  
317
    @Override
313 318
    public void addComposerMenu(String text, Action action) {
314 319
        String name = (String) action.getValue(Action.ACTION_COMMAND_KEY);
315 320
        this.composerMenus.put(name,new DefaultMenuEntry(text,action));
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/DefaultJScriptingConsole.java
3 3
import org.gvsig.scripting.swing.api.JScriptingConsole;
4 4
import java.awt.BorderLayout;
5 5
import java.awt.Color;
6
import java.awt.Component;
6 7
import java.awt.Font;
7 8
import java.awt.event.ComponentEvent;
8 9
import java.awt.event.ComponentListener;
......
13 14
import javax.swing.JPanel;
14 15
import javax.swing.JScrollPane;
15 16
import javax.swing.JTextPane;
17
import javax.swing.plaf.ComponentUI;
16 18
import javax.swing.text.AttributeSet;
17 19
import javax.swing.text.SimpleAttributeSet;
18 20
import javax.swing.text.StyleConstants;
19 21
import javax.swing.text.StyleContext;
20 22

  
21

  
22 23
public class DefaultJScriptingConsole extends JPanel implements JScriptingConsole {
24
    private static final long serialVersionUID = -1181983617272717357L;
23 25

  
24 26
    private JTextAreaOutputStream stdout = null;
25 27
    private JTextAreaOutputStream stderr = null;
26 28
    private JTextPane console;
29
    private boolean captureOutput;
27 30

  
28
    public DefaultJScriptingConsole() {
31
    public DefaultJScriptingConsole(boolean captureOutput) {
32
        this.captureOutput = captureOutput;
33
        
34
        this.initComponents();
29 35

  
30
        this.initComponents();
31
        
32 36
        this.stdout = new JTextAreaOutputStream(System.out, Color.BLACK);
33 37
        this.stderr = new JTextAreaOutputStream(System.err, Color.RED.darker());
34
        
35
        
38

  
36 39
        this.addComponentListener(new ComponentListener() {
37 40

  
38 41
            @Override
......
45 48

  
46 49
            @Override
47 50
            public void componentShown(ComponentEvent e) {
48
                if( System.out != stdout.getPrintStream() ) {
49
                    System.setOut(stdout.getPrintStream(System.out));
51
                if( canCaptureOutput() ) {
52
                    if ( System.out != stdout.getPrintStream()) {
53
                        System.setOut(stdout.getPrintStream(System.out));
54
                    }
55
                    if ( System.err != stderr.getPrintStream()) {
56
                        System.setErr(stderr.getPrintStream(System.err));
57
                    }
50 58
                }
51
                if( System.err != stderr.getPrintStream() ) {
52
                    System.setErr(stderr.getPrintStream(System.err));
53
                }
54 59
            }
55 60

  
56 61
            @Override
57 62
            public void componentHidden(ComponentEvent e) {
58
                System.setOut(stdout.getOriginalPS());
59
                System.setErr(stderr.getOriginalPS());
63
                if( canCaptureOutput() ) {
64
                    if ( System.out != stdout.getPrintStream()) {
65
                        System.setOut(stdout.getOriginalPS());
66
                    }
67
                    if ( System.err != stderr.getPrintStream()) {
68
                        System.setErr(stderr.getOriginalPS());
69
                    }
70
                }
60 71
            }
61 72
        });
62 73
    }
74

  
75
    private boolean canCaptureOutput() {
76
        return this.captureOutput;
77
    }
63 78
    
64
    private void initComponents(){
79
    private void initComponents() {
65 80
        this.setLayout(new BorderLayout());
66
        console = new JTextPane();
81
        console = new JTextPane() {
82
            private static final long serialVersionUID = -1309476113717086242L;
83

  
84
            // https://tips4java.wordpress.com/2009/01/25/no-wrap-text-pane/
85

  
86
            @Override
87
            public boolean getScrollableTracksViewportWidth() {
88
                Component parent = getParent();
89
                ComponentUI ui = getUI();
90

  
91
                return parent != null ? (ui.getPreferredSize(this).width <= parent
92
                        .getSize().width) : true;
93
            }
94
        };
67 95
        console.setFont(new Font("monospaced", Font.PLAIN, 13));
68 96
        JScrollPane scrollConsole = new JScrollPane(console);
69 97
        this.add(scrollConsole, BorderLayout.CENTER);
70 98
    }
71
    
99

  
72 100
    @Override
73 101
    public void clear() {
74 102
        this.console.setText("");
......
78 106
    public void append(String s) {
79 107
        append(s, stdout.color);
80 108
    }
81
    
109

  
82 110
    @Override
83 111
    public void append(String msg, Color color) {
84 112
        StyleContext sc = StyleContext.getDefaultStyleContext();
......
87 115
        int len = console.getDocument().getLength();
88 116
        console.setCaretPosition(len);
89 117
        console.setCharacterAttributes(aset, false);
90
        console.replaceSelection(msg);        
118
        console.replaceSelection(msg);
91 119
    }
92
    
120

  
93 121
    @Override
94 122
    public PrintStream getStdout() {
95 123
        return this.stdout.getPrintStream();
96 124
    }
97
    
125

  
98 126
    @Override
99 127
    public PrintStream getStderr() {
100 128
        return this.stderr.getPrintStream();
......
104 132
    public JComponent asJComponent() {
105 133
        return this;
106 134
    }
107
    
135

  
108 136
    private class JTextAreaOutputStream extends OutputStream {
109 137

  
110 138
        PrintStream printStream = null;
......
129 157
            append(s, color);
130 158
            originalPS.write(buf, off, len);
131 159
        }
132
        
160

  
133 161
        public PrintStream getPrintStream() {
134
            if( this.printStream == null ) {
162
            if (this.printStream == null) {
135 163
                this.printStream = new PrintStream(this);
136 164
            }
137 165
            return this.printStream;
......
147 175
        }
148 176
    }
149 177

  
150

  
151 178
}
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/DefaultJScriptingComposer.java
68 68
import org.gvsig.scripting.CompileErrorException;
69 69
import org.gvsig.scripting.ExecuteErrorException;
70 70
import org.gvsig.scripting.ScriptingBaseScript;
71
import org.gvsig.scripting.ScriptingErrorException;
71 72
import org.gvsig.scripting.ScriptingFolder;
72 73
import org.gvsig.scripting.ScriptingManager;
73 74
import org.gvsig.scripting.ScriptingNotification;
......
78 79
import org.gvsig.scripting.swing.api.JScriptingBrowser;
79 80
import org.gvsig.scripting.swing.api.JScriptingBrowser.BrowserActionEvent;
80 81
import org.gvsig.scripting.swing.api.JScriptingComposer;
82
import static org.gvsig.scripting.swing.api.JScriptingComposer.DOCKED_PROBLEMS;
81 83
import org.gvsig.scripting.swing.api.JScriptingComposer.Dock.DockedPanel;
82 84
import org.gvsig.scripting.swing.api.JScriptingComposer.Problems;
83 85
import org.gvsig.scripting.swing.api.JScriptingComposer.Problems.Problem;
......
89 91
import org.gvsig.scripting.swing.impl.DefaultJScriptingConsole;
90 92
import org.gvsig.scripting.swing.impl.DefaultScriptingUIManager;
91 93
import org.gvsig.scripting.swing.impl.JDialogContent;
94
import org.gvsig.scripting.swing.impl.composer.DefaultJScriptingComposer.DefaultProblems.ProblemsTableMode.DefaultProblem;
92 95
import org.gvsig.tools.ToolsLocator;
93 96
import org.gvsig.tools.i18n.I18nManager;
94 97
import org.gvsig.tools.observer.Observable;
......
938 941
                }
939 942
                Problem row = problems.getSelect();
940 943
                if (row != null) {
944
                    JEditor editor;
941 945
                    int lineno = row.getLineNumber();
942
                    JEditor editor = getCurrentEditor();
943
                    if (editor instanceof JCodeEditor) {
944
                        ((JCodeEditor) editor).selectLine(lineno);
946
                    if( row.getResource() == null ) {
947
                        editor = getCurrentEditor();
948
                    } else {
949
                        String id = row.getResource().getAbsolutePath();
950
                        DockedPanel panel = getDock().get(id);
951
                        if( panel == null ) {
952
                            ScriptingBaseScript script = manager.getScript(row.getResource());
953
                            scriptEdit(script);
954
                            panel = getDock().get(id);
955
                            if( panel == null ) {
956
                                logger.warn("Can't load script '"+id+"'.");
957
                                return;
958
                            }
959
                        } 
960
                        panel.select();
961
                        editor = (JEditor) panel.getComponent();
945 962
                    }
963
                    if ( editor instanceof JCodeEditor) {
964
                        ((JCodeEditor) editor).gotoline(lineno);
965
                    }
946 966
                }
947 967
            }
948 968
        });
......
961 981
            panel.select();
962 982
            return;
963 983
        }
964
        DefaultJScriptingConsole console = new DefaultJScriptingConsole();
984
        DefaultJScriptingConsole console = new DefaultJScriptingConsole(true);
965 985
        this.dock.add(
966 986
                DOCKED_CONSOLE,
967 987
                this.uimanager.getTranslation("Console"),
......
1120 1140
    }
1121 1141

  
1122 1142
    public void scriptEdit(ScriptingBaseScript unit) {
1123
        String id = unit.getFile().getAbsolutePath();
1143
        String id = unit.getScriptFile().getAbsolutePath();
1124 1144
        DockedPanel x = this.dock.get(id);
1125 1145
        if (x != null) {
1126 1146
            x.select();
......
1544 1564
                CompileErrorException ce = (CompileErrorException) e.getException();
1545 1565
                Problems problems = this.getProblems();
1546 1566
                if (problems != null) {
1547
                    problems.add(
1548
                            "Error",
1549
                            ce.getMessage(),
1550
                            ce.getScriptName(),
1551
                            ce.getLineNumber(),
1552
                            ce.getColumnNumber()
1553
                    );
1567
                    problems.add("Error", ce);
1554 1568
                    this.dock.select(DOCKED_PROBLEMS);
1555 1569
                }
1556 1570

  
......
1558 1572
                ExecuteErrorException ee = (ExecuteErrorException) e.getException();
1559 1573
                Problems problems = this.getProblems();
1560 1574
                if (problems != null) {
1561
                    problems.add(
1562
                            "Error",
1563
                            ee.getMessage(),
1564
                            ee.getScriptName(),
1565
                            ee.getLineNumber(),
1566
                            ee.getColumnNumber()
1567
                    );
1575
                    problems.add("Error",ee);
1568 1576
                    this.dock.select(DOCKED_PROBLEMS);
1569 1577
                }
1570 1578
                JScriptingConsole console = this.getConsole();
......
1574 1582
                }
1575 1583

  
1576 1584
            } else {
1577
                Throwable ex = e.getException();
1585
                Exception ex = e.getException();
1578 1586
                Problems problems = this.getProblems();
1579 1587
                if (problems != null) {
1580
                    problems.add(
1581
                            "Error",
1582
                            ex.getMessage(),
1583
                            null,
1584
                            null
1585
                    );
1588
                    problems.add("Error",ex); 
1586 1589
                    this.dock.select(DOCKED_PROBLEMS);
1587 1590
                }
1588 1591
                JScriptingConsole console = this.getConsole();
......
1814 1817
            public static class DefaultProblem implements Problem {
1815 1818

  
1816 1819
                String[] row;
1820
                private File resource;
1817 1821

  
1822
                public DefaultProblem() {
1823
                    this.row = new String[NUM_COLUMNS];
1824
                }
1825

  
1818 1826
                public DefaultProblem(String[] row) {
1819 1827
                    this.row = row;
1820 1828
                }
1821 1829

  
1822
                public DefaultProblem(String type, String message, String resource, String location) {
1830
                public DefaultProblem(String type, String message, String resourceName, String location, File resource) {
1823 1831
                    String[] row = new String[NUM_COLUMNS];
1824 1832
                    row[COLUMN_TYPE] = type;
1825 1833
                    row[COLUMN_MESSAGE] = message;
1826
                    row[COLUMN_RESOURCE] = resource;
1834
                    row[COLUMN_RESOURCE] = resourceName;
1827 1835
                    row[COLUMN_LOCATION] = location;
1836
                    this.resource = resource;
1828 1837
                    this.row = row;
1829 1838
                }
1830 1839

  
......
1851 1860
                }
1852 1861

  
1853 1862
                @Override
1854
                public String getResource() {
1863
                public String getResourceName() {
1855 1864
                    return this.row[COLUMN_RESOURCE];
1856 1865
                }
1857 1866

  
1858 1867
                @Override
1868
                public File getResource() {
1869
                    return this.resource;
1870
                }
1871

  
1872
                @Override
1859 1873
                public int getLineNumber() {
1860 1874
                    try {
1861 1875
                        String[] lineAndColumn = this.row[COLUMN_LOCATION].split(":");
......
1897 1911
                this.fireTableDataChanged();
1898 1912
            }
1899 1913

  
1900
            private void add(String type, String message, String resource, String location) {
1901
                DefaultProblem problem = new DefaultProblem(type, message, resource, location);
1914
            private void add(String type, String message, String resourceName, String location, File resource) {
1915
                DefaultProblem problem = new DefaultProblem(type, message, resourceName, location, resource);
1902 1916
                this.add(problem);
1903 1917
            }
1904 1918

  
......
2005 2019

  
2006 2020
        @Override
2007 2021
        public void add(String type, String message, String resource, String location) {
2008
            this.tableModel.add(type, message, resource, location);
2022
            this.tableModel.add(type, message, resource, location, null);
2009 2023
        }
2010 2024

  
2011 2025
        @Override
2012 2026
        public void add(String type, String message, String resource, int line, int column) {
2013 2027
            this.add(type, message, resource, line + ":" + column);
2014 2028
        }
2029
        
2030
        public void add(String type, String message, String resourceName, int line, int column, File resource) {
2031
            this.tableModel.add(type, message, resourceName, line + ":" + column, resource);
2032
        }
2033
                
2034
        @Override
2035
        public void add(String type, Exception e) {
2036
            if (e  instanceof ScriptingErrorException) {
2037
                ScriptingErrorException se = (ScriptingErrorException) e;
2038
                    this.add(
2039
                        "Error",
2040
                        se.getMessage(),
2041
                        se.getScriptName(),
2042
                        se.getLineNumber(),
2043
                        se.getColumnNumber(),
2044
                        se.getScriptFile()
2045
                    );
2015 2046

  
2047
            } else {
2048
                    this.add("Error", 
2049
                        "Error",
2050
                        e.getMessage(),
2051
                        null
2052
                    );
2053
            }            
2054
        }
2055

  
2016 2056
        @Override
2017 2057
        public Problem getSelect() {
2018 2058
            int row = this.table.getSelectedRow();
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/pom.xml
90 90
            <groupId>org.gvsig</groupId>
91 91
            <artifactId>org.gvsig.installer.swing.api</artifactId>
92 92
            <scope>compile</scope>
93
        </dependency>
93
        </dependency>      
94 94
    </dependencies>
95 95
    <build>
96 96
        <plugins>

Also available in: Unified diff