@@ -16,27 +16,38 @@ package org.utplsql.sqldev.editor.menu
16
16
17
17
import java.util.logging.Logger
18
18
import javax.swing.JEditorPane
19
+ import oracle.dbtools.raptor.navigator.impl.DatabaseSourceNode
20
+ import oracle.dbtools.raptor.utils.Connections
21
+ import oracle.dbtools.worksheet.editor.OpenWorksheetWizard
22
+ import oracle.dbtools.worksheet.editor.Worksheet
19
23
import oracle.ide.Context
20
24
import oracle.ide.Ide
25
+ import oracle.ide.config.Preferences
21
26
import oracle.ide.controller.Controller
22
27
import oracle.ide.controller.IdeAction
23
28
import oracle.ide.editor.Editor
24
29
import oracle.ide.^extension.RegisteredByExtension
30
+ import oracle.ide.model.Node
31
+ import org.utplsql.sqldev.model.preference.PreferenceModel
25
32
import org.utplsql.sqldev.parser.UtplsqlParser
33
+ import org.utplsql.sqldev.resources.UtplsqlResources
26
34
27
35
@RegisteredByExtension (" org.utplsql.sqldev" )
28
36
class UtplsqlEditorController implements Controller {
29
37
public static int UTLPLSQL_EDITOR_TEST_CMD_ID = Ide . findCmdID(" utplsql.editor.test" )
30
38
private static final Logger logger = Logger . getLogger(UtplsqlEditorController . name);
31
-
39
+
32
40
override handleEvent (IdeAction action , Context context ) {
33
41
if (action. commandId == = UTLPLSQL_EDITOR_TEST_CMD_ID ) {
34
- runTest(context)
42
+ val Runnable runnable = [|runTest(context)]
43
+ val thread = new Thread (runnable)
44
+ thread. name = " utPLSQL run test"
45
+ thread. start
35
46
return true
36
47
}
37
48
return false
38
49
}
39
-
50
+
40
51
override update (IdeAction action , Context context ) {
41
52
if (action. commandId == = UTLPLSQL_EDITOR_TEST_CMD_ID ) {
42
53
action. enabled = false
@@ -54,20 +65,50 @@ class UtplsqlEditorController implements Controller {
54
65
}
55
66
return false
56
67
}
57
-
68
+
58
69
def runTest (Context context ) {
59
70
logger. fine(" Start utPLSQL test from editor." )
71
+ logger. fine(' ' ' context.view is of type «context.view.class.name».' ' ' )
72
+ logger. fine(' ' ' context.node is of type «context.node.class.name».' ' ' )
60
73
val view = context. view
61
74
if (view instanceof Editor ) {
62
75
val component = view. defaultFocusComponent
63
76
if (component instanceof JEditorPane ) {
64
77
val parser = new UtplsqlParser (component. text)
65
78
val position = component. caretPosition
66
- // TODO: open new worksheet and call utPLSQL
79
+ var String connectionName = null ;
80
+ val Node node = context. node
81
+ if (node instanceof DatabaseSourceNode ) {
82
+ connectionName = node. connectionName
83
+ } else if (view instanceof Worksheet ) {
84
+ connectionName = view. connectionName
85
+ }
86
+ val preferences = PreferenceModel . getInstance(Preferences . getPreferences());
87
+ if (connectionName !== null && preferences. unsharedWorksheet) {
88
+ connectionName = Connections . instance. createPrivateConnection(connectionName)
89
+ }
90
+ val code = ' ' '
91
+ SET SERVEROUTPUT ON SIZE 1000000
92
+ «IF preferences.resetPackage»
93
+ BEGIN
94
+ dbms_session.reset_package;
95
+ END;
96
+ /
97
+ «ENDIF»
98
+ BEGIN
99
+ ut.run(' «parser. getPathAt(position)»' );
100
+ END;
101
+ /
102
+ ' ' '
103
+ val worksheet = OpenWorksheetWizard . openNewTempWorksheet(connectionName, code) as Worksheet
104
+ if (connectionName == = null ) {
105
+ worksheet. comboConnection = null
106
+ }
107
+ // TODO make update Title work
108
+ worksheet. updateTitle(UtplsqlResources . getString(" WORKSHEET_TITLE" ))
109
+ // TODO exeucte code in worksheet when preferences.autoExecute
67
110
logger. fine(' ' ' Cursor is at «position». Calling «parser.getPathAt(position)»' ' ' )
68
111
}
69
112
}
70
- logger. fine (" utPLSQL test started successfully." )
71
113
}
72
-
73
114
}
0 commit comments