Skip to content

Commit 65eb3be

Browse files
enable/disable context menu "Generate utPLSQL test"
1 parent 15831d1 commit 65eb3be

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

sqldev/src/main/java/org/utplsql/sqldev/menu/UtplsqlController.xtend

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class UtplsqlController implements Controller {
4444
val extension URLTools urlTools = new URLTools
4545

4646
public static int UTLPLSQL_TEST_CMD_ID = Ide.findCmdID("utplsql.test")
47+
public static int UTLPLSQL_GENERATE_CMD_ID = Ide.findCmdID("utplsql.generate")
4748
public static final IdeAction UTLPLSQL_TEST_ACTION = IdeAction.get(UtplsqlController.UTLPLSQL_TEST_CMD_ID)
49+
public static final IdeAction UTLPLSQL_GENERATE_ACTION = IdeAction.get(UtplsqlController.UTLPLSQL_GENERATE_CMD_ID)
4850

4951
override handleEvent(IdeAction action, Context context) {
5052
if (action.commandId === UtplsqlController.UTLPLSQL_TEST_CMD_ID) {
@@ -110,6 +112,28 @@ class UtplsqlController implements Controller {
110112
}
111113
}
112114
return true
115+
} else if (action.commandId === UTLPLSQL_GENERATE_CMD_ID) {
116+
action.enabled = false
117+
// enable if generation is possible
118+
val view = context.view
119+
if (view instanceof Editor) {
120+
val component = view.defaultFocusComponent
121+
if (component instanceof JEditorPane) {
122+
val parser = new UtplsqlParser(component.text)
123+
action.enabled = parser.getObjectAt(component.caretPosition) !== null
124+
}
125+
} else if (view instanceof DBNavigatorWindow) {
126+
// multiselection is not supported, use oddgen to generte tests for multiple objects
127+
if (context.selection.length == 1) {
128+
val element = context.selection.get(0)
129+
if (element instanceof PlSqlNode) {
130+
val ot = element.objectType
131+
if (ot.startsWith("PACKAGE") || ot.startsWith("TYPE") || ot == "FUNCTION" || ot == "PROCEDURE") {
132+
action.enabled = true
133+
}
134+
}
135+
}
136+
}
113137
}
114138
return false
115139
}

0 commit comments

Comments
 (0)