Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sqldeveloper/extension/.classpath
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/built/gen-src"/>
<classpathentry kind="src" path="java/InsertTemplateAction/built/gen-src"/>
<classpathentry kind="src" path="java/InsertTemplateAction/src"/>
<classpathentry kind="src" path="java/ContextMenuAction/built/gen-src"/>
<classpathentry kind="src" path="java/ContextMenuAction/src"/>
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/src"/>
<classpathentry kind="src" path="java/DumpObjectTypesAction/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/FXDiagram 0.35.0-SNAPSHOT"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/KIELER KLay Layouters v. 2015.02"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SQLDeveloper 18.1"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SQLDeveloper 19.2"/>
<classpathentry kind="output" path="built/classes"/>
</classpath>
40 changes: 20 additions & 20 deletions sqldeveloper/extension/build.properties
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Definitions for things that are likely static for a given environment
# You can override these in the local build.properties if needed by
# loading the local properties file before including buildtools/ant/build.xml
# Where sqldev lives. The directory that sqldeveloper/bin is in.
# This is where the builds will deploy the extension
# and where we can find our dependencies
#sqldev.dir=D:/sqldeveloper-4.2.0.17.089.1709/sqldeveloper
sqldev.dir=D:/sqldeveloper-18.1.0/sqldeveloper
# Information about the company or person creating the extension
extension.owner=Oracle Examples
extension.owner.desc=Example extensions for SQL Developer
extension.owner.url=https://github.com/oracle/oracle-db-examples/tree/master/sqldeveloper/extension
#
# Base location of the CFU site.
# This is where the produced updates.xml will say the cfu bundle files are.
update.url=https://gitcdn.xyz/repo/bjeffrie/sqldev-update-center/master
# Definitions for things that are likely static for a given environment
# You can override these in the local build.properties if needed by
# loading the local properties file before including buildtools/ant/build.xml

# Where sqldev lives. The directory that sqldeveloper/bin is in.
# This is where the builds will deploy the extension
# and where we can find our dependencies
#sqldev.dir=D:/sqldeveloper-4.2.0.17.089.1709/sqldeveloper
sqldev.dir=D:/sqldeveloper-19.2.1/sqldeveloper

# Information about the company or person creating the extension
extension.owner=Oracle Examples
extension.owner.desc=Example extensions for SQL Developer
extension.owner.url=https://github.com/oracle/oracle-db-examples/tree/master/sqldeveloper/extension

#
# Base location of the CFU site.
# This is where the produced updates.xml will say the cfu bundle files are.
update.url=https://gitcdn.xyz/repo/bjeffrie/sqldev-update-center/master

6 changes: 6 additions & 0 deletions sqldeveloper/extension/java/InsertTemplateAction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SQL Developer Examples
## InsertTemplateAction
A quick context menu action on code editor to insert a template string for @maternaDev01

NOTE: This example inserts a static string.
TODO: Template from (json, text, xml?) files
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extension.id=oracle.db.example.sqldeveloper.extension.insertTemplateAction
extension.name=Insert insertTemplateAction Action
extension.descr=Example context menu action on code editor to insert a template
extension.version=18.1.0
extension.resources=oracle.db.example.sqldeveloper.extension.insertTemplateAction.ExtensionResources

extension.lib=external:$oracle.fcp.home$/sqldeveloper/extensions/${extension.id}/lib
osgi.bundle.classpath=.
22 changes: 22 additions & 0 deletions sqldeveloper/extension/java/InsertTemplateAction/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="windows-1252" ?>
<project name="InsertTemplateAction" default="_deploy">
<!-- imports -->
<import file="../../buildtools/ant/build.xml" />

<!-- bundle dependencies -->
<property name="osgi.required.bundles"
value="${osgi.bundle.default.dependencies},${osgi.bundle.sqldev},${osgi.bundle.utils-nodeps},${osgi.bundle.utils}" />

<!-- classpath declarations -->
<path id="local.classpath">
<path refid="oracle.sqldeveloper.utils-nodeps"/>
<path refid="oracle.sqldeveloper.utils"/>
<path refid="oracle.sqldeveloper" />
</path>

<!-- local targets -->

<!-- target overrides -->
<!-- Build structure from ../../buildtools/ant/build.xml < targets.xml -->

</project>
149 changes: 149 additions & 0 deletions sqldeveloper/extension/java/InsertTemplateAction/etc/extension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

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.
-->

<extension xmlns="http://jcp.org/jsr/198/extension-manifest"
id="@@extension.id@@" version="@@extension.version@@.@@extension.build@@"
esdk-version="1.0"
rsbundle-class="@@extension.resources@@">

<name>@@extension.name@@</name>
<owner>@@extension.owner@@ @@extension.owner.url@@</owner>

<!--
<feature-category xmlns="http://xmlns.oracle.com/ide/extension" id="example-category">
<name>${CATEGORY_NAME}</name>
<description>${CATEGORY_DESCRIPTION}</description>
</feature-category>
Duplicate category definitions cause a severe error to be logged.
Only way around it from the outside I can think of is an extension just to add
the category and all the others dependent on it.
The pre-defined ones are:
{db-category=Database, ide-category=IDE, db-migrations-category=Database Migrations,
database-category=Database Development, java-se-category=Java SE,
vcs-category=Version Control, xml-category=XML}
and example-category=Examples, if you've installed the XMLPackedExample
Not supplying a category or giving a non-existent one will just show the extension
at the root of the features tree.
-->
<feature id="@@extension.id@@" xmlns="http://xmlns.oracle.com/ide/extension">
<name>@@extension.name@@</name>
<description>@@extension.descr@@</description>
<type>
<service can-user-disable="true" reload-if-used="true"/>
</type>
</feature>
<trigger-hooks xmlns="http://xmlns.oracle.com/ide/extension">
<rules>
<!-- Need to have rule for the declarations below, but it is a "severe"
exception to duplicate them. Need to collate a list of the existing
ones - seems there would be little chance new ones are really needed. -->

<!-- See ActionController.doAction - we are counting on this -->
<rule id="insertTemplateAction-view-is-editorPaneContainer" type="context-has-view">
<parameters>
<param name="view-class" value="oracle.javatools.editor.BasicEditorPaneContainer"/>
</parameters>
</rule>
</rules>
<triggers xmlns:c="http://xmlns.oracle.com/ide/customization">
<actions xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
<action id="InsertTemplateAction_ID">
<properties>
<property name="Name">${ACTION_LABEL}</property>
<!-- You could also use your own by putting path in rsbundle
e.g., MY_ICON = /oracle/db/example/sqldeveloper/extension/dependency/icons/my_icon.png
and referencing its key as res:${MY_ICON} -->
<!-- <property name="SmallIcon">${OracleIcons.DUKE}</property> -->
</properties>
</action>
</actions>
<controllers xmlns="http://xmlns.oracle.com/ide/extension">
<controller class="oracle.db.example.sqldeveloper.extension.insertTemplateAction.ActionController">
<!-- Not needed if the context-menu-hook is using a rule to determine if it shows up at all? -->
<update-rules>
<update-rule rule="insertTemplateAction-view-is-editorPaneContainer">
<action id="InsertTemplateAction_ID"/>
</update-rule>
</update-rules>
</controller>
</controllers>
<context-menu-hook rule="insertTemplateAction-view-is-editorPaneContainer">
<site idref="editor"/> <!-- can do multiple e.g.;, "db_nav;editor" -->
<menu>
<section xmlns="http://jcp.org/jsr/198/extension-manifest" id="SECTION_WINDOW_CTXT_MENU" weight="1.0">
<item action-ref="InsertTemplateAction_ID" weight="1.0"/>
</section>
</menu>
</context-menu-hook>

<!-- When placed here in the trigger-hooks section, these will be loaded right away -->
<sqldev-action-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-actions">
<!-- This is the directory to read all action *.xml from
<actionDescriptor package="oracle.db.example.sqldeveloper.extension.dependency.action"/>
-->
</sqldev-action-hook>
<sqldev-navigator-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-navigator">
<!-- These are the navigator XML files to read
<descriptor>/oracle/db/example/sqldeveloper/extension/dependency/navigator/DependencyExampleNavigator.xml</descriptor>
-->
</sqldev-navigator-hook>
<!-- viewer-hook cannot be a trigger -->
<!-- BUT doing this will add a menu toggle entry in the connection
context menu for Manage Features->your feature for users to
enable/disable xml based things with requiredFeatures="your dynamic id"
See oracle.db.example.sqldeveloper.extension.dependency.viewer.DependencyExampleGraphViewer.xml
AS A SIDE EFFECT, enabling it the 1st time will fully load the extension
-->
<!-- Need to check on this. Works in current dev version, but not EA1.
SO FOR NOW, you have to use the context menu show viewer once then object viewers
opened afterwards will have the dependency viewer tab -->
<!--
<sqldev-feature-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-feature">
<dynamicFeature id="dependencyObjectViewerExample">${DEPENDENCY_VIEWER_TAB_LABEL}</dynamicFeature>
</sqldev-feature-hook>
-->
</triggers>
</trigger-hooks>
<hooks>
<jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
<addins>
<!--
<addin>oracle.db.example.sqldeveloper.extension.dumpObjectTypes.DumpObjectTypesAddin</addin>
-->
</addins>
</jdeveloper-hook>
<!-- When placed here in the hooks section, these won't be loaded until the extension is by one of the above triggers -->
<sqldev-action-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-actions">
<!-- This is the directory to read all action *.xml from
<actionDescriptor package="oracle.db.example.sqldeveloper.extension.dependency.action.xml"/>
-->
</sqldev-action-hook>
<sqldev-navigator-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-navigator">
<!-- These are the navigator XML files to read
<descriptor>oracle.db.example.sqldeveloper.extension.dependency/navigator/DependencyExampleNavigator.xml</descriptor>
-->
</sqldev-navigator-hook>
<!-- viewer-hook cannot be a trigger -->
<sqldev-viewer-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-viewers">
<!-- This is the directory to read all viewer *.xml from
<viewerDescriptor package="oracle.db.example.sqldeveloper.extension.dependency.viewer"/>
-->
</sqldev-viewer-hook>

</hooks>

</extension>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oracle.db.example.sqldeveloper.extension.insertTemplateAction.ExtensionResources
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

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 oracle.db.example.sqldeveloper.extension.insertTemplateAction;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import oracle.ide.Context;
import oracle.ide.Ide;
import oracle.ide.controller.Controller;
import oracle.ide.controller.IdeAction;
import oracle.ide.view.View;
import oracle.javatools.editor.BasicEditorPane;
import oracle.javatools.editor.BasicEditorPaneContainer;

/**
* ActionController
*
* @author <a href=
* "mailto:brian.jeffries@oracle.com?subject=oracle.db.example.sqldeveloper.extension.insertTemplateAction.ActionController">Brian
* Jeffries</a>
* @since SQL Developer 19.3
*/

public class ActionController implements Controller {
public static int ACTION_CMD = Ide.findOrCreateCmdID("InsertTemplateAction_ID"); //$NON-NLS-1$

@Override
public boolean handleEvent(IdeAction action, Context context) {
int cmdId = action.getCommandId();
if (ACTION_CMD == cmdId) {
doAction(context);
return true; // (I handled it)
}
return false; // Not my job, ask other controllers
}

@Override
public boolean update(IdeAction action, Context context) {
int cmdId = action.getCommandId();
if (ACTION_CMD == cmdId) {
// If it is cheap and fast, figure out a real answer
// else just enable it and let handleEvent deal with
// it.
action.setEnabled(true);
return true; // required for trigger hook actions
}
return false; // Not my job, ask other controllers
}

private void doAction(Context context) {
final View view = context.getView();
final BasicEditorPane editor = ((BasicEditorPaneContainer) view).getFocusedEditorPane();

loadMacros();
String templateText = getTemplateText();
String outputText = processMacros(templateText);

// this will insert at caret if there is no selection, else replace the
// selection
editor.replaceSelection(outputText);

}

private String getTemplateText() {
// TODO: get from file
return "-- insertTemplateText Example\n-- @@USER@@@@@HOSTNAME@@ @@DATE@@\n";
}

private Map<String, String> macroMap = new HashMap<>();

private void loadMacros() {
// Some may be time sensitive so always reload
//System.out.println(String.valueOf(System.getenv()).replace(",", ",\n"));
//System.out.println(String.valueOf(System.getProperties()).replace(",", ",\n"));
macroMap.clear();
macroMap.put("@@USER@@", System.getenv("USERNAME"));
macroMap.put("@@HOSTNAME@@", System.getenv("HOSTNAME"));
macroMap.put("@@DATE@@", LocalDateTime.now().toString());
return;
}

private String processMacros(String in) {
if (null == in || in.isEmpty()) {
return in;
}
String out = in;
for (String macro : macroMap.keySet()) {
String replacement = macroMap.get(macro);
if (replacement != null && !replacement.isEmpty()) {
out = out.replace(macro, replacement);
}
}
return out;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ACTION_LABEL = Insert Template
# {0} = template(file?) name - not sure we can/will use this
SUB_MENU_LABEL = {0}
3 changes: 3 additions & 0 deletions sqldeveloper/extension/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ A quick object action to dump the list of connection / objects types as INFO mes
* [ContextMenuAction](ContextMenuAction)
A quick context menu action on FUNCTION, PROCEDURE code editor to insert a static string and
a PLDoc template if PL/Scope information is available.

* [InsertTemplateAction](InsertTemplateAction)
A quick context menu action on code editor to insert a template string for @maternaDev01
Loading