Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 14fd8bc

Browse files
Merge pull request #77 from oracle/maternaDev01-62
Add InsertTemplateAction example
2 parents c690fc5 + 2281c6a commit 14fd8bc

File tree

13 files changed

+386
-68
lines changed

13 files changed

+386
-68
lines changed

‎sqldeveloper/extension/.classpath‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/built/gen-src"/>
4+
<classpathentry kind="src" path="java/InsertTemplateAction/built/gen-src"/>
5+
<classpathentry kind="src" path="java/InsertTemplateAction/src"/>
46
<classpathentry kind="src" path="java/ContextMenuAction/built/gen-src"/>
57
<classpathentry kind="src" path="java/ContextMenuAction/src"/>
68
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/src"/>
79
<classpathentry kind="src" path="java/DumpObjectTypesAction/src"/>
810
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
911
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/FXDiagram 0.35.0-SNAPSHOT"/>
1012
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/KIELER KLay Layouters v. 2015.02"/>
11-
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SQLDeveloper 18.1"/>
13+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SQLDeveloper 19.2"/>
1214
<classpathentry kind="output" path="built/classes"/>
1315
</classpath>
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Definitions for things that are likely static for a given environment
2-
# You can override these in the local build.properties if needed by
3-
# loading the local properties file before including buildtools/ant/build.xml
4-
5-
# Where sqldev lives. The directory that sqldeveloper/bin is in.
6-
# This is where the builds will deploy the extension
7-
# and where we can find our dependencies
8-
#sqldev.dir=D:/sqldeveloper-4.2.0.17.089.1709/sqldeveloper
9-
sqldev.dir=D:/sqldeveloper-18.1.0/sqldeveloper
10-
11-
# Information about the company or person creating the extension
12-
extension.owner=Oracle Examples
13-
extension.owner.desc=Example extensions for SQL Developer
14-
extension.owner.url=https://github.com/oracle/oracle-db-examples/tree/master/sqldeveloper/extension
15-
16-
#
17-
# Base location of the CFU site.
18-
# This is where the produced updates.xml will say the cfu bundle files are.
19-
update.url=https://gitcdn.xyz/repo/bjeffrie/sqldev-update-center/master
20-
1+
# Definitions for things that are likely static for a given environment
2+
# You can override these in the local build.properties if needed by
3+
# loading the local properties file before including buildtools/ant/build.xml
4+
5+
# Where sqldev lives. The directory that sqldeveloper/bin is in.
6+
# This is where the builds will deploy the extension
7+
# and where we can find our dependencies
8+
#sqldev.dir=D:/sqldeveloper-4.2.0.17.089.1709/sqldeveloper
9+
sqldev.dir=D:/sqldeveloper-19.2.1/sqldeveloper
10+
11+
# Information about the company or person creating the extension
12+
extension.owner=Oracle Examples
13+
extension.owner.desc=Example extensions for SQL Developer
14+
extension.owner.url=https://github.com/oracle/oracle-db-examples/tree/master/sqldeveloper/extension
15+
16+
#
17+
# Base location of the CFU site.
18+
# This is where the produced updates.xml will say the cfu bundle files are.
19+
update.url=https://gitcdn.xyz/repo/bjeffrie/sqldev-update-center/master
20+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SQL Developer Examples
2+
## InsertTemplateAction
3+
A quick context menu action on code editor to insert a template string for @maternaDev01
4+
5+
NOTE: This example inserts a static string.
6+
TODO: Template from (json, text, xml?) files
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extension.id=oracle.db.example.sqldeveloper.extension.insertTemplateAction
2+
extension.name=Insert insertTemplateAction Action
3+
extension.descr=Example context menu action on code editor to insert a template
4+
extension.version=18.1.0
5+
extension.resources=oracle.db.example.sqldeveloper.extension.insertTemplateAction.ExtensionResources
6+
7+
extension.lib=external:$oracle.fcp.home$/sqldeveloper/extensions/${extension.id}/lib
8+
osgi.bundle.classpath=.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="windows-1252" ?>
2+
<project name="InsertTemplateAction" default="_deploy">
3+
<!-- imports -->
4+
<import file="../../buildtools/ant/build.xml" />
5+
6+
<!-- bundle dependencies -->
7+
<property name="osgi.required.bundles"
8+
value="${osgi.bundle.default.dependencies},${osgi.bundle.sqldev},${osgi.bundle.utils-nodeps},${osgi.bundle.utils}" />
9+
10+
<!-- classpath declarations -->
11+
<path id="local.classpath">
12+
<path refid="oracle.sqldeveloper.utils-nodeps"/>
13+
<path refid="oracle.sqldeveloper.utils"/>
14+
<path refid="oracle.sqldeveloper" />
15+
</path>
16+
17+
<!-- local targets -->
18+
19+
<!-- target overrides -->
20+
<!-- Build structure from ../../buildtools/ant/build.xml < targets.xml -->
21+
22+
</project>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<extension xmlns="http://jcp.org/jsr/198/extension-manifest"
19+
id="@@extension.id@@" version="@@extension.version@@.@@extension.build@@"
20+
esdk-version="1.0"
21+
rsbundle-class="@@extension.resources@@">
22+
23+
<name>@@extension.name@@</name>
24+
<owner>@@extension.owner@@ @@extension.owner.url@@</owner>
25+
26+
<!--
27+
<feature-category xmlns="http://xmlns.oracle.com/ide/extension" id="example-category">
28+
<name>${CATEGORY_NAME}</name>
29+
<description>${CATEGORY_DESCRIPTION}</description>
30+
</feature-category>
31+
Duplicate category definitions cause a severe error to be logged.
32+
Only way around it from the outside I can think of is an extension just to add
33+
the category and all the others dependent on it.
34+
The pre-defined ones are:
35+
{db-category=Database, ide-category=IDE, db-migrations-category=Database Migrations,
36+
database-category=Database Development, java-se-category=Java SE,
37+
vcs-category=Version Control, xml-category=XML}
38+
and example-category=Examples, if you've installed the XMLPackedExample
39+
Not supplying a category or giving a non-existent one will just show the extension
40+
at the root of the features tree.
41+
-->
42+
<feature id="@@extension.id@@" xmlns="http://xmlns.oracle.com/ide/extension">
43+
<name>@@extension.name@@</name>
44+
<description>@@extension.descr@@</description>
45+
<type>
46+
<service can-user-disable="true" reload-if-used="true"/>
47+
</type>
48+
</feature>
49+
<trigger-hooks xmlns="http://xmlns.oracle.com/ide/extension">
50+
<rules>
51+
<!-- Need to have rule for the declarations below, but it is a "severe"
52+
exception to duplicate them. Need to collate a list of the existing
53+
ones - seems there would be little chance new ones are really needed. -->
54+
55+
<!-- See ActionController.doAction - we are counting on this -->
56+
<rule id="insertTemplateAction-view-is-editorPaneContainer" type="context-has-view">
57+
<parameters>
58+
<param name="view-class" value="oracle.javatools.editor.BasicEditorPaneContainer"/>
59+
</parameters>
60+
</rule>
61+
</rules>
62+
<triggers xmlns:c="http://xmlns.oracle.com/ide/customization">
63+
<actions xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
64+
<action id="InsertTemplateAction_ID">
65+
<properties>
66+
<property name="Name">${ACTION_LABEL}</property>
67+
<!-- You could also use your own by putting path in rsbundle
68+
e.g., MY_ICON = /oracle/db/example/sqldeveloper/extension/dependency/icons/my_icon.png
69+
and referencing its key as res:${MY_ICON} -->
70+
<!-- <property name="SmallIcon">${OracleIcons.DUKE}</property> -->
71+
</properties>
72+
</action>
73+
</actions>
74+
<controllers xmlns="http://xmlns.oracle.com/ide/extension">
75+
<controller class="oracle.db.example.sqldeveloper.extension.insertTemplateAction.ActionController">
76+
<!-- Not needed if the context-menu-hook is using a rule to determine if it shows up at all? -->
77+
<update-rules>
78+
<update-rule rule="insertTemplateAction-view-is-editorPaneContainer">
79+
<action id="InsertTemplateAction_ID"/>
80+
</update-rule>
81+
</update-rules>
82+
</controller>
83+
</controllers>
84+
<context-menu-hook rule="insertTemplateAction-view-is-editorPaneContainer">
85+
<site idref="editor"/> <!-- can do multiple e.g.;, "db_nav;editor" -->
86+
<menu>
87+
<section xmlns="http://jcp.org/jsr/198/extension-manifest" id="SECTION_WINDOW_CTXT_MENU" weight="1.0">
88+
<item action-ref="InsertTemplateAction_ID" weight="1.0"/>
89+
</section>
90+
</menu>
91+
</context-menu-hook>
92+
93+
<!-- When placed here in the trigger-hooks section, these will be loaded right away -->
94+
<sqldev-action-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-actions">
95+
<!-- This is the directory to read all action *.xml from
96+
<actionDescriptor package="oracle.db.example.sqldeveloper.extension.dependency.action"/>
97+
-->
98+
</sqldev-action-hook>
99+
<sqldev-navigator-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-navigator">
100+
<!-- These are the navigator XML files to read
101+
<descriptor>/oracle/db/example/sqldeveloper/extension/dependency/navigator/DependencyExampleNavigator.xml</descriptor>
102+
-->
103+
</sqldev-navigator-hook>
104+
<!-- viewer-hook cannot be a trigger -->
105+
<!-- BUT doing this will add a menu toggle entry in the connection
106+
context menu for Manage Features->your feature for users to
107+
enable/disable xml based things with requiredFeatures="your dynamic id"
108+
See oracle.db.example.sqldeveloper.extension.dependency.viewer.DependencyExampleGraphViewer.xml
109+
AS A SIDE EFFECT, enabling it the 1st time will fully load the extension
110+
-->
111+
<!-- Need to check on this. Works in current dev version, but not EA1.
112+
SO FOR NOW, you have to use the context menu show viewer once then object viewers
113+
opened afterwards will have the dependency viewer tab -->
114+
<!--
115+
<sqldev-feature-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-feature">
116+
<dynamicFeature id="dependencyObjectViewerExample">${DEPENDENCY_VIEWER_TAB_LABEL}</dynamicFeature>
117+
</sqldev-feature-hook>
118+
-->
119+
</triggers>
120+
</trigger-hooks>
121+
<hooks>
122+
<jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
123+
<addins>
124+
<!--
125+
<addin>oracle.db.example.sqldeveloper.extension.dumpObjectTypes.DumpObjectTypesAddin</addin>
126+
-->
127+
</addins>
128+
</jdeveloper-hook>
129+
<!-- When placed here in the hooks section, these won't be loaded until the extension is by one of the above triggers -->
130+
<sqldev-action-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-actions">
131+
<!-- This is the directory to read all action *.xml from
132+
<actionDescriptor package="oracle.db.example.sqldeveloper.extension.dependency.action.xml"/>
133+
-->
134+
</sqldev-action-hook>
135+
<sqldev-navigator-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-navigator">
136+
<!-- These are the navigator XML files to read
137+
<descriptor>oracle.db.example.sqldeveloper.extension.dependency/navigator/DependencyExampleNavigator.xml</descriptor>
138+
-->
139+
</sqldev-navigator-hook>
140+
<!-- viewer-hook cannot be a trigger -->
141+
<sqldev-viewer-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-viewers">
142+
<!-- This is the directory to read all viewer *.xml from
143+
<viewerDescriptor package="oracle.db.example.sqldeveloper.extension.dependency.viewer"/>
144+
-->
145+
</sqldev-viewer-hook>
146+
147+
</hooks>
148+
149+
</extension>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oracle.db.example.sqldeveloper.extension.insertTemplateAction.ExtensionResources
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package oracle.db.example.sqldeveloper.extension.insertTemplateAction;
18+
19+
import java.time.LocalDateTime;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
import oracle.ide.Context;
24+
import oracle.ide.Ide;
25+
import oracle.ide.controller.Controller;
26+
import oracle.ide.controller.IdeAction;
27+
import oracle.ide.view.View;
28+
import oracle.javatools.editor.BasicEditorPane;
29+
import oracle.javatools.editor.BasicEditorPaneContainer;
30+
31+
/**
32+
* ActionController
33+
*
34+
* @author <a href=
35+
* "mailto:brian.jeffries@oracle.com?subject=oracle.db.example.sqldeveloper.extension.insertTemplateAction.ActionController">Brian
36+
* Jeffries</a>
37+
* @since SQL Developer 19.3
38+
*/
39+
40+
public class ActionController implements Controller {
41+
public static int ACTION_CMD = Ide.findOrCreateCmdID("InsertTemplateAction_ID"); //$NON-NLS-1$
42+
43+
@Override
44+
public boolean handleEvent(IdeAction action, Context context) {
45+
int cmdId = action.getCommandId();
46+
if (ACTION_CMD == cmdId) {
47+
doAction(context);
48+
return true; // (I handled it)
49+
}
50+
return false; // Not my job, ask other controllers
51+
}
52+
53+
@Override
54+
public boolean update(IdeAction action, Context context) {
55+
int cmdId = action.getCommandId();
56+
if (ACTION_CMD == cmdId) {
57+
// If it is cheap and fast, figure out a real answer
58+
// else just enable it and let handleEvent deal with
59+
// it.
60+
action.setEnabled(true);
61+
return true; // required for trigger hook actions
62+
}
63+
return false; // Not my job, ask other controllers
64+
}
65+
66+
private void doAction(Context context) {
67+
final View view = context.getView();
68+
final BasicEditorPane editor = ((BasicEditorPaneContainer) view).getFocusedEditorPane();
69+
70+
loadMacros();
71+
String templateText = getTemplateText();
72+
String outputText = processMacros(templateText);
73+
74+
// this will insert at caret if there is no selection, else replace the
75+
// selection
76+
editor.replaceSelection(outputText);
77+
78+
}
79+
80+
private String getTemplateText() {
81+
// TODO: get from file
82+
return "-- insertTemplateText Example\n-- @@USER@@@@@HOSTNAME@@ @@DATE@@\n";
83+
}
84+
85+
private Map<String, String> macroMap = new HashMap<>();
86+
87+
private void loadMacros() {
88+
// Some may be time sensitive so always reload
89+
//System.out.println(String.valueOf(System.getenv()).replace(",", ",\n"));
90+
//System.out.println(String.valueOf(System.getProperties()).replace(",", ",\n"));
91+
macroMap.clear();
92+
macroMap.put("@@USER@@", System.getenv("USERNAME"));
93+
macroMap.put("@@HOSTNAME@@", System.getenv("HOSTNAME"));
94+
macroMap.put("@@DATE@@", LocalDateTime.now().toString());
95+
return;
96+
}
97+
98+
private String processMacros(String in) {
99+
if (null == in || in.isEmpty()) {
100+
return in;
101+
}
102+
String out = in;
103+
for (String macro : macroMap.keySet()) {
104+
String replacement = macroMap.get(macro);
105+
if (replacement != null && !replacement.isEmpty()) {
106+
out = out.replace(macro, replacement);
107+
}
108+
}
109+
return out;
110+
}
111+
112+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ACTION_LABEL = Insert Template
2+
# {0} = template(file?) name - not sure we can/will use this
3+
SUB_MENU_LABEL = {0}

‎sqldeveloper/extension/java/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ A quick object action to dump the list of connection / objects types as INFO mes
1616
* [ContextMenuAction](ContextMenuAction)
1717
A quick context menu action on FUNCTION, PROCEDURE code editor to insert a static string and
1818
a PLDoc template if PL/Scope information is available.
19+
20+
* [InsertTemplateAction](InsertTemplateAction)
21+
A quick context menu action on code editor to insert a template string for @maternaDev01

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /