diff --git a/sqldeveloper/extension/.classpath b/sqldeveloper/extension/.classpath index c5e9f0bc..50e68e06 100644 --- a/sqldeveloper/extension/.classpath +++ b/sqldeveloper/extension/.classpath @@ -1,6 +1,8 @@ + + @@ -8,6 +10,6 @@ - + diff --git a/sqldeveloper/extension/build.properties b/sqldeveloper/extension/build.properties index 6710a9fc..f8021e79 100644 --- a/sqldeveloper/extension/build.properties +++ b/sqldeveloper/extension/build.properties @@ -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 + diff --git a/sqldeveloper/extension/java/InsertTemplateAction/README.md b/sqldeveloper/extension/java/InsertTemplateAction/README.md new file mode 100644 index 00000000..e31354a9 --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/README.md @@ -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 diff --git a/sqldeveloper/extension/java/InsertTemplateAction/build.properties b/sqldeveloper/extension/java/InsertTemplateAction/build.properties new file mode 100644 index 00000000..0f81ab0a --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/build.properties @@ -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=. diff --git a/sqldeveloper/extension/java/InsertTemplateAction/build.xml b/sqldeveloper/extension/java/InsertTemplateAction/build.xml new file mode 100644 index 00000000..38eae7c8 --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/build.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sqldeveloper/extension/java/InsertTemplateAction/etc/extension.xml b/sqldeveloper/extension/java/InsertTemplateAction/etc/extension.xml new file mode 100644 index 00000000..80b6ab52 --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/etc/extension.xml @@ -0,0 +1,149 @@ + + + + + + @@extension.name@@ + @@extension.owner@@ @@extension.owner.url@@ + + + + @@extension.name@@ + @@extension.descr@@ + + + + + + + + + + + + + + + + + + + + ${ACTION_LABEL} + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/sqldeveloper/extension/java/InsertTemplateAction/resfiles.properties b/sqldeveloper/extension/java/InsertTemplateAction/resfiles.properties new file mode 100644 index 00000000..3edc43bd --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/resfiles.properties @@ -0,0 +1 @@ +oracle.db.example.sqldeveloper.extension.insertTemplateAction.ExtensionResources \ No newline at end of file diff --git a/sqldeveloper/extension/java/InsertTemplateAction/src/oracle/db/example/sqldeveloper/extension/insertTemplateAction/ActionController.java b/sqldeveloper/extension/java/InsertTemplateAction/src/oracle/db/example/sqldeveloper/extension/insertTemplateAction/ActionController.java new file mode 100644 index 00000000..d49e38ff --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/src/oracle/db/example/sqldeveloper/extension/insertTemplateAction/ActionController.java @@ -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 Brian + * Jeffries + * @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 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; + } + +} diff --git a/sqldeveloper/extension/java/InsertTemplateAction/src/oracle/db/example/sqldeveloper/extension/insertTemplateAction/ExtensionResources.properties b/sqldeveloper/extension/java/InsertTemplateAction/src/oracle/db/example/sqldeveloper/extension/insertTemplateAction/ExtensionResources.properties new file mode 100644 index 00000000..160da23c --- /dev/null +++ b/sqldeveloper/extension/java/InsertTemplateAction/src/oracle/db/example/sqldeveloper/extension/insertTemplateAction/ExtensionResources.properties @@ -0,0 +1,3 @@ +ACTION_LABEL = Insert Template +# {0} = template(file?) name - not sure we can/will use this +SUB_MENU_LABEL = {0} diff --git a/sqldeveloper/extension/java/README.md b/sqldeveloper/extension/java/README.md index 5ac7a84d..f6366b0d 100644 --- a/sqldeveloper/extension/java/README.md +++ b/sqldeveloper/extension/java/README.md @@ -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 diff --git a/sqldeveloper/extension/java/SQLDeveloper18.1.userlibraries b/sqldeveloper/extension/java/SQLDeveloper.userlibraries similarity index 76% rename from sqldeveloper/extension/java/SQLDeveloper18.1.userlibraries rename to sqldeveloper/extension/java/SQLDeveloper.userlibraries index 7004cee8..86b5c676 100644 --- a/sqldeveloper/extension/java/SQLDeveloper18.1.userlibraries +++ b/sqldeveloper/extension/java/SQLDeveloper.userlibraries @@ -1,43 +1,55 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sqldeveloper/extension/setenv.bat b/sqldeveloper/extension/setenv.bat index b0910a80..d892e00b 100644 --- a/sqldeveloper/extension/setenv.bat +++ b/sqldeveloper/extension/setenv.bat @@ -1,6 +1,6 @@ SET ANT_HOME=D:\apache-ant-1.10.3 -SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_152 +SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181 SET ANT_BIN=%ANT_HOME%\bin -SET SQLDEV_BIN=D:\sqldeveloper-18.1.0\sqldeveloper\sqldeveloper\bin +SET SQLDEV_BIN=D:\sqldeveloper-19.2.1\sqldeveloper\sqldeveloper\bin SET PATH=%PATH%;%ANT_BIN%;%SQLDEV_BIN% diff --git a/sqldeveloper/extension/setup.md b/sqldeveloper/extension/setup.md index 5e24d3b6..044bd4e5 100644 --- a/sqldeveloper/extension/setup.md +++ b/sqldeveloper/extension/setup.md @@ -3,7 +3,7 @@ ## First things first: Getting the pieces ### Java JDK 8 -We are currently using [jdk1.8.0_152](http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html) +We are currently using [jdk1.8](http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html) ### SQL Developer You'll need a copy of [SQL Developer](http://www.oracle.com/technetwork/developer-tools/sql-developer/) both as a deployment location for testing and as the source for required library files. @@ -32,7 +32,7 @@ sqldeveloper/extension is an eclipse project directory but the examples are buil * extension/build.properties - Update to point to your SQL Developer installation & optionally change the owner info. -* extension/java/SQLDeveloper18.1.userlibraries - **IF** you are using eclipse, update the paths to point to your SQL Developer installation and import the library. +* extension/java/SQLDeveloper.userlibraries - **IF** you are using eclipse, update the paths to point to your SQL Developer installation and import the library. ### Third party libraries **If/when** you plan to build the [Dependency Example](java/DependencyExample), see that page for additional set up requirements.