Skip to content

Commit 7d656bf

Browse files
committed
Add an "Elements" view plugin.
1 parent 0a2ad07 commit 7d656bf

12 files changed

+413
-0
lines changed

web-author-elements-view/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
.settings/
3+
.classpath
4+
.project

web-author-elements-view/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Web Author Elements View
2+
========================
3+
4+
A plugin that contributes an 'Elements' view that displays elements that can be inserted at the caret position

web-author-elements-view/assembly.xml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- This is an assembly file used for all the sample plugins. -->
2+
3+
<assembly
4+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
7+
<id>plugin</id>
8+
<formats>
9+
<format>jar</format>
10+
</formats>
11+
12+
<fileSets>
13+
<fileSet>
14+
<directory>web</directory>
15+
<outputDirectory>web</outputDirectory>
16+
<includes>
17+
<include>**/*</include>
18+
</includes>
19+
</fileSet>
20+
21+
<fileSet>
22+
<directory>target/lib</directory>
23+
<outputDirectory>lib</outputDirectory>
24+
<includes>
25+
<include>**/*</include>
26+
</includes>
27+
</fileSet>
28+
</fileSets>
29+
30+
<files>
31+
<file>
32+
<source>target/build/${project.build.finalName}.jar</source>
33+
<outputDirectory>lib</outputDirectory>
34+
</file>
35+
<file>
36+
<source>plugin.xml</source>
37+
<filtered>true</filtered>
38+
</file>
39+
</files>
40+
41+
</assembly>
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This folder was added here to be easier to download the plugin, although it is not best practice to commit JAR files in the Git repo.
2+
3+
If the Java code is modified, the JAR needs to be updated.
6.56 KB
Binary file not shown.
Binary file not shown.

web-author-elements-view/plugin.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- The plugin.dtd file is located in the OXYGEN_INSATALL_DIR/plugins directory -->
3+
<!DOCTYPE plugin SYSTEM "../plugin.dtd">
4+
5+
<plugin
6+
class="com.oxygenxml.webapp.elements.SamplePluginExtension"
7+
8+
id="web-author-elements-view"
9+
name="Web Author Elements View"
10+
description="A plugin that contributes an 'Elements' view that displays elements that can be inserted at the caret position"
11+
version="1.0"
12+
vendor="Syncro Soft SRL">
13+
14+
<runtime>
15+
<library name="target/classes" />
16+
<librariesFolder name="target/lib" />
17+
<librariesFolder name="lib" />
18+
</runtime>
19+
</plugin>

web-author-elements-view/pom.xml

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.oxygenxml</groupId>
8+
<artifactId>web-author-elements-view</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<developers>
12+
<developer>
13+
<name>Cristi Talau</name>
14+
<email>[email protected]</email>
15+
<roles>
16+
<role>manager</role>
17+
</roles>
18+
</developer>
19+
</developers>
20+
21+
<properties>
22+
<oxygen.sdk.version>22.0.0.0</oxygen.sdk.version>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<maven.compiler.source>1.8</maven.compiler.source>
25+
<maven.compiler.target>1.8</maven.compiler.target>
26+
</properties>
27+
28+
<repositories>
29+
<repository>
30+
<id>oxygenxml</id>
31+
<name>oXygen XML SDK Maven Repository</name>
32+
<url>https://oxygenxml.com/maven/</url>
33+
</repository>
34+
</repositories>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>com.oxygenxml</groupId>
39+
<artifactId>oxygen-sdk</artifactId>
40+
<version>${oxygen.sdk.version}</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>javax.servlet</groupId>
46+
<artifactId>javax.servlet-api</artifactId>
47+
<version>3.0.1</version>
48+
<scope>provided</scope>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<finalName>${project.artifactId}-${project.version}</finalName>
54+
<plugins>
55+
<!-- remove the -SNAPSHOT from packaged plugin -->
56+
<plugin>
57+
<groupId>org.codehaus.mojo</groupId>
58+
<artifactId>build-helper-maven-plugin</artifactId>
59+
<version>1.10</version>
60+
<executions>
61+
<execution>
62+
<id>set-version-no-snapshot</id>
63+
<goals>
64+
<goal>regex-property</goal>
65+
</goals>
66+
<configuration>
67+
<name>project.nosnapshot.version</name>
68+
<value>${project.version}</value>
69+
<regex>-SNAPSHOT</regex>
70+
<replacement></replacement>
71+
<failIfNoMatch>false</failIfNoMatch>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
<plugin>
77+
<artifactId>maven-dependency-plugin</artifactId>
78+
<version>2.8</version>
79+
<executions>
80+
<execution>
81+
<phase>generate-resources</phase>
82+
<goals>
83+
<goal>copy-dependencies</goal>
84+
</goals>
85+
<configuration>
86+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
87+
<includeScope>runtime</includeScope>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-jar-plugin</artifactId>
95+
<version>2.2</version>
96+
<configuration>
97+
<!-- We only want the final JAR package in the target folder so that it's easier for users to identify it.-->
98+
<outputDirectory>${project.build.directory}/build</outputDirectory>
99+
</configuration>
100+
</plugin>
101+
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-assembly-plugin</artifactId>
105+
<version>2.6</version>
106+
<executions>
107+
<execution>
108+
<id>make-assembly</id>
109+
<phase>package</phase>
110+
<goals>
111+
<goal>single</goal>
112+
</goals>
113+
<configuration>
114+
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
115+
<descriptors>
116+
<descriptor>assembly.xml</descriptor>
117+
</descriptors>
118+
</configuration>
119+
</execution>
120+
</executions>
121+
</plugin>
122+
</plugins>
123+
124+
<pluginManagement>
125+
<plugins>
126+
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
127+
<plugin>
128+
<groupId>org.eclipse.m2e</groupId>
129+
<artifactId>lifecycle-mapping</artifactId>
130+
<version>1.0.0</version>
131+
<configuration>
132+
<lifecycleMappingMetadata>
133+
<pluginExecutions>
134+
<pluginExecution>
135+
<pluginExecutionFilter>
136+
<groupId>org.codehaus.mojo</groupId>
137+
<artifactId>
138+
build-helper-maven-plugin
139+
</artifactId>
140+
<versionRange>[1.10,)</versionRange>
141+
<goals>
142+
<goal>regex-property</goal>
143+
</goals>
144+
</pluginExecutionFilter>
145+
<action>
146+
<ignore></ignore>
147+
</action>
148+
</pluginExecution>
149+
</pluginExecutions>
150+
</lifecycleMappingMetadata>
151+
</configuration>
152+
</plugin>
153+
</plugins>
154+
</pluginManagement>
155+
156+
</build>
157+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.oxygenxml.webapp.elements;
2+
3+
import static java.util.stream.Collectors.joining;
4+
5+
import java.util.List;
6+
7+
import javax.swing.text.BadLocationException;
8+
9+
import ro.sync.ecss.extensions.api.ArgumentsMap;
10+
import ro.sync.ecss.extensions.api.AuthorOperationException;
11+
import ro.sync.ecss.extensions.api.webapp.AuthorDocumentModel;
12+
import ro.sync.ecss.extensions.api.webapp.AuthorOperationWithResult;
13+
import ro.sync.ecss.extensions.api.webapp.WebappRestSafe;
14+
import ro.sync.ecss.extensions.api.webapp.cc.CCItemProxy;
15+
16+
/**
17+
* Operation to return elements to insert.
18+
* @author cristi_talau
19+
*/
20+
@WebappRestSafe
21+
public class GetElementsValidToInsert extends AuthorOperationWithResult {
22+
23+
@Override
24+
public String doOperation(AuthorDocumentModel model, ArgumentsMap args)
25+
throws AuthorOperationException {
26+
try {
27+
List<CCItemProxy> forInsert = model.getContentCompletionManager().getProposedElementsForInsert(model.getSelectionModel());
28+
return forInsert.stream().map(CCItemProxy::getDisplayName).collect(joining(","));
29+
} catch (BadLocationException e) {
30+
throw new AuthorOperationException(e.getMessage(), e);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.oxygenxml.webapp.elements;
2+
3+
import java.util.List;
4+
5+
import javax.swing.text.BadLocationException;
6+
7+
import ro.sync.ecss.extensions.api.ArgumentsMap;
8+
import ro.sync.ecss.extensions.api.AuthorOperationException;
9+
import ro.sync.ecss.extensions.api.webapp.AuthorDocumentModel;
10+
import ro.sync.ecss.extensions.api.webapp.AuthorOperationWithResult;
11+
import ro.sync.ecss.extensions.api.webapp.WebappRestSafe;
12+
import ro.sync.ecss.extensions.api.webapp.cc.CCItemProxy;
13+
import ro.sync.ecss.extensions.api.webapp.cc.ContentCompletionManager;
14+
import ro.sync.ecss.extensions.api.webapp.cc.ItemNotFoundException;
15+
16+
/**
17+
* Insert element from content completion.
18+
*
19+
* @author cristi_talau
20+
*/
21+
@WebappRestSafe
22+
public class InsertElementFromContentCompletion extends AuthorOperationWithResult {
23+
24+
@Override
25+
public String doOperation(AuthorDocumentModel model, ArgumentsMap args) throws AuthorOperationException {
26+
String name = (String) args.getArgumentValue("name");
27+
try {
28+
ContentCompletionManager contentCompletionManager = model.getContentCompletionManager();
29+
List<CCItemProxy> forInsert = contentCompletionManager.getProposedElementsForInsert(model.getSelectionModel());
30+
CCItemProxy foundItem = forInsert.stream()
31+
.filter(item -> item.getDisplayName().equals(name))
32+
.findAny()
33+
.orElseThrow(IllegalArgumentException::new);
34+
contentCompletionManager.executeInsert(foundItem, model.getSelectionModel());
35+
return "success";
36+
} catch (BadLocationException e) {
37+
throw new AuthorOperationException(e.getMessage(), e);
38+
} catch (ItemNotFoundException e) {
39+
throw new IllegalArgumentException(e);
40+
}
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.oxygenxml.webapp.elements;
2+
3+
import ro.sync.exml.plugin.Plugin;
4+
import ro.sync.exml.plugin.PluginDescriptor;
5+
6+
/**
7+
* Sample extension for <code>ro.sync.exml.plugin.Plugin</code>.
8+
*/
9+
public class SamplePluginExtension extends Plugin {
10+
11+
/**
12+
* Constructor.
13+
* @param descriptor Plug-in descriptor.
14+
*/
15+
public SamplePluginExtension(PluginDescriptor descriptor) {
16+
super(descriptor);
17+
}
18+
}

0 commit comments

Comments
 (0)