Skip to content

Commit

Permalink
fixes #4 - add accelerator in connections navigator
Browse files Browse the repository at this point in the history
removed XML based actions and implemented a a ContextMenuListener and a Controller
  • Loading branch information
PhilippSalvisberg committed Jan 30, 2018
1 parent ade6a38 commit f98feec
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 165 deletions.
22 changes: 14 additions & 8 deletions sqldev/extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@

<trigger-hooks xmlns="http://xmlns.oracle.com/ide/extension">
<triggers>
<sqldev-action-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-actions">
<actionDescriptor package="org.utplsql.sqldev.actions" />
</sqldev-action-hook>
<actions xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
<action id="utplsql.editor.test">
<action id="utplsql.test">
<properties>
<property name="Name">${MENU_RUN_TEST_LABEL}</property>
<property name="SmallIcon">res:/org/utplsql/sqldev/resources/images/utPLSQL.png</property>
Expand All @@ -28,10 +25,10 @@
</action>
</actions>
<controllers xmlns="http://xmlns.oracle.com/ide/extension">
<controller class="org.utplsql.sqldev.editor.menu.UtplsqlEditorController">
<controller class="org.utplsql.sqldev.menu.UtplsqlController">
<update-rules>
<update-rule rule="always-enabled">
<action id="utplsql.editor.test"/>
<action id="utplsql.test"/>
</update-rule>
</update-rules>
</controller>
Expand All @@ -40,8 +37,8 @@
<site idref="editor" />
<menu>
<section xmlns="http://jcp.org/jsr/198/extension-manifest"
id="UTPLSQL_EDITOR_MENU" weight="2.0">
<item action-ref="utplsql.editor.test" weight="1.0"/>
id="UTPLSQL_MENU" weight="2.0">
<item action-ref="utplsql.test" weight="1.0"/>
</section>
</menu>
</context-menu-hook>
Expand All @@ -57,4 +54,13 @@
</settings-ui-hook>
</triggers>
</trigger-hooks>
<hooks xmlns:c="http://xmlns.oracle.com/ide/customization">
<jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
<context-menu-listeners>
<site idref="db_nav">
<listener-class>org.utplsql.sqldev.menu.UtplsqlContextMenuListener</listener-class>
</site>
</context-menu-listeners>
</jdeveloper-hook>
</hooks>
</extension>
10 changes: 8 additions & 2 deletions sqldev/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@
<scope>system</scope>
<systemPath>${sqldev.basedir}/jdev/extensions/oracle.jdeveloper.db.connection.jar</systemPath>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>oracle.jdeveloper.java.core.jar</artifactId>
<version>12.2.1</version>
<scope>system</scope>
<systemPath>${sqldev.basedir}/jdev/extensions/oracle.jdeveloper.java.core.jar</systemPath>
</dependency>
<!-- SQL Developer specific dependencies part 2 (available in public maven repositories) -->
<dependency>
<!-- SQL Developer is using this older version -->
Expand Down Expand Up @@ -389,9 +396,8 @@
</Include-Resource>
<Export-Package>
org.utplsql.sqldev,
org.utplsql.sqldev.editor.menu,
org.utplsql.sqldev.menu,
org.utplsql.sqldev.model.preference,
org.utplsql.sqldev.navigator.menu,
org.utplsql.sqldev.actions,
org.utplsql.sqldev.resources
</Export-Package>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.utplsql.sqldev.menu

import java.util.logging.Logger
import oracle.dbtools.raptor.navigator.db.DatabaseConnection
import oracle.dbtools.raptor.navigator.impl.ChildObjectElement
import oracle.dbtools.raptor.navigator.impl.ObjectFolder
import oracle.dbtools.raptor.navigator.plsql.PlSqlNode
import oracle.ide.Context
import oracle.ide.controller.ContextMenu
import oracle.ide.controller.ContextMenuListener
import org.utplsql.sqldev.model.URLTools

class UtplsqlContextMenuListener implements ContextMenuListener {
private static final Logger logger = Logger.getLogger(UtplsqlContextMenuListener.name);
private val extension URLTools urlTools = new URLTools


override handleDefaultAction(Context context) {
return false
}

override menuWillHide(ContextMenu contextMenu) {
}

override menuWillShow(ContextMenu contextMenu) {
val element = contextMenu.context.selection.get(0)
var boolean showMenu = false
logger.fine('''selected object is of type «element.class.name»''')
if (element instanceof DatabaseConnection) {
showMenu = true
} else if (element instanceof ObjectFolder) {
if (element.objectType == "PACKAGE" || element.objectType == "TYPE") {
showMenu = true
}
} else if (element instanceof PlSqlNode) {
if (element.objectType == "PACKAGE" || element.objectType == "PACKAGE BODY" ||
element.objectType == "TYPE" || element.objectType == "TYPE BODY") {
showMenu = true
}
} else if (element instanceof ChildObjectElement) {
if (element.URL.objectType == "PACKAGE" || element.URL.objectType == "TYPE") {
showMenu = true
}
}
if (showMenu) {
val menuItem = contextMenu.createMenuItem(UtplsqlController.UTLPLSQL_TEST_ACTION, 1.0f)
contextMenu.add(menuItem, 12.1f)
logger.finer("context menu created.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.utplsql.sqldev.editor.menu
package org.utplsql.sqldev.menu

import java.net.URL
import java.util.logging.Logger
import javax.swing.JEditorPane
import oracle.dbtools.raptor.navigator.db.DBNavigatorWindow
import oracle.dbtools.raptor.navigator.db.DatabaseConnection
import oracle.dbtools.raptor.navigator.impl.ChildObjectElement
import oracle.dbtools.raptor.navigator.impl.DatabaseSourceNode
import oracle.dbtools.raptor.navigator.impl.ObjectFolder
import oracle.dbtools.raptor.navigator.plsql.PlSqlNode
import oracle.dbtools.worksheet.editor.Worksheet
import oracle.ide.Context
import oracle.ide.Ide
import oracle.ide.controller.Controller
import oracle.ide.controller.IdeAction
import oracle.ide.editor.Editor
import oracle.ide.^extension.RegisteredByExtension
import org.utplsql.sqldev.UtplsqlWorksheet
import org.utplsql.sqldev.model.URLTools
import org.utplsql.sqldev.parser.UtplsqlParser

@RegisteredByExtension("org.utplsql.sqldev")
class UtplsqlEditorController implements Controller {
public static int UTLPLSQL_EDITOR_TEST_CMD_ID = Ide.findCmdID("utplsql.editor.test")
private static final Logger logger = Logger.getLogger(UtplsqlEditorController.name);
class UtplsqlController implements Controller {
private static final Logger logger = Logger.getLogger(UtplsqlController.name);
private val extension URLTools urlTools = new URLTools

public static int UTLPLSQL_TEST_CMD_ID = Ide.findCmdID("utplsql.test")
public static final IdeAction UTLPLSQL_TEST_ACTION = IdeAction.get(UtplsqlController.UTLPLSQL_TEST_CMD_ID)

override handleEvent(IdeAction action, Context context) {
if (action.commandId === UTLPLSQL_EDITOR_TEST_CMD_ID) {
if (action.commandId === UtplsqlController.UTLPLSQL_TEST_CMD_ID) {
runTest(context)
return true
}
return false
}

override update(IdeAction action, Context context) {
if (action.commandId === UTLPLSQL_EDITOR_TEST_CMD_ID) {
if (action.commandId === UTLPLSQL_TEST_CMD_ID) {
action.enabled = false
val view = context.view
if (view instanceof Editor) {
Expand All @@ -52,16 +60,54 @@ class UtplsqlEditorController implements Controller {
action.enabled = true
}
}
} else if (view instanceof DBNavigatorWindow) {
if (context.selection.length == 1) {
action.enabled = true
}
}
return true
}
return false
}

private def getPath(Context context) {
var String path
val element = context.selection.get(0)
if (element instanceof DatabaseConnection) {
path = element.connection.schema
} else if (element instanceof ObjectFolder) {
path = element.URL.schema
} else if (element instanceof PlSqlNode) {
path = '''«element.owner».«element.objectName»'''
} else if (element instanceof ChildObjectElement) {
path = '''«element.URL.schema».«element.URL.memberObject».«element.shortLabel»'''
} else {
path = ""
}
logger.fine('''path: «path»''')
return path
}

private def getURL(Context context) {
var URL url
val element = context.selection.get(0)
if (element instanceof DatabaseConnection) {
url = element.URL
} else if (element instanceof ObjectFolder) {
url = element.URL
} else if (element instanceof PlSqlNode) {
url = element.URL
} else if (element instanceof ChildObjectElement) {
url = element.URL
}
logger.fine('''url: «url»''')
return url
}

def runTest(Context context) {
val view = context.view
val node = context.node
logger.finer('''Run utPLSQL from editor with view «view.class.name» and node «node.class.name».''')
logger.finer('''Run utPLSQL from view «view?.class?.name» and node «node?.class?.name».''')
if (view instanceof Editor) {
val component = view.defaultFocusComponent
if (component instanceof JEditorPane) {
Expand All @@ -74,6 +120,16 @@ class UtplsqlEditorController implements Controller {
} else if (view instanceof Worksheet) {
connectionName = view.connectionName
}
logger.fine('''connectionName: «connectionName»''')
val utPlsqlWorksheet = new UtplsqlWorksheet(path, connectionName)
utPlsqlWorksheet.runTestAsync
}
} else if (view instanceof DBNavigatorWindow) {
val url=context.URL
if (url !== null) {
val connectionName = url.connectionName
logger.fine('''connectionName: «connectionName»''')
val path=context.path
val utPlsqlWorksheet = new UtplsqlWorksheet(path, connectionName)
utPlsqlWorksheet.runTestAsync
}
Expand Down
61 changes: 61 additions & 0 deletions sqldev/src/main/java/org/utplsql/sqldev/model/URLTools.xtend
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.utplsql.sqldev.model

import java.net.URL
import java.util.regex.Pattern

class URLTools {
def getConnectionName(URL url) {
val p = Pattern.compile("(sqldev.nav:)([^/]+)(//)?")
val m = p.matcher(url.toString)
if (m.find) {
return m.group(2).replace("IdeConnections%2523", "IdeConnections%23")
} else {
return ""
}
}

def getSchema(URL url) {
val p = Pattern.compile("(//)([^/]+)")
val m = p.matcher(url.toString)
if (m.find) {
return m.group(2)
} else {
return ""
}
}

def getObjectType(URL url) {
val p = Pattern.compile("(//)([^/]+)(/)([^/]+)")
val m = p.matcher(url.toString)
if (m.find) {
return m.group(4)
} else {
return ""
}
}

def getMemberObject(URL url) {
val p = Pattern.compile("(/)([^/]+)(#MEMBER)")
val m = p.matcher(url.toString)

if (m.find) {
return m.group(2)
} else {
return ""
}
}
}

This file was deleted.

Loading

0 comments on commit f98feec

Please sign in to comment.