Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSnjezana Peco2016-06-07 20:48:14 +0000
committerVictor Rubezhny2016-07-12 20:30:29 +0000
commit07916459b156d0776fc2fe1d97fb42c840c93f42 (patch)
treea43bd7f6f810c2e7101a2e4455f4892f98dc7c3b
parenta858a2730bbe9b082a9b1af02abc5c04666230ba (diff)
downloadwebtools.sourceediting-07916459b156d0776fc2fe1d97fb42c840c93f42.tar.gz
webtools.sourceediting-07916459b156d0776fc2fe1d97fb42c840c93f42.tar.xz
webtools.sourceediting-07916459b156d0776fc2fe1d97fb42c840c93f42.zip
Bug 494185 - Template 'new package.json' should be available only for package.json file
Change-Id: I8f7c48fcda782a2bb667b0cdcaf202831a3b6414 Signed-off-by: Snjezana Peco <snjeza.peco@gmail.com>
-rw-r--r--bundles/org.eclipse.wst.json.ui/plugin.properties2
-rw-r--r--bundles/org.eclipse.wst.json.ui/plugin.xml14
-rw-r--r--bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIPlugin.java128
-rw-r--r--bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONPackageTemplatesCompletionProposalComputer.java94
-rw-r--r--bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeIdsJSON.java2
-rw-r--r--bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml2
6 files changed, 176 insertions, 66 deletions
diff --git a/bundles/org.eclipse.wst.json.ui/plugin.properties b/bundles/org.eclipse.wst.json.ui/plugin.properties
index 1df7d33a91..22cb8113f9 100644
--- a/bundles/org.eclipse.wst.json.ui/plugin.properties
+++ b/bundles/org.eclipse.wst.json.ui/plugin.properties
@@ -40,4 +40,4 @@ proposalCategory.jsonTemplates=JSON Template Proposals
All_JSON_context_type_Extension_Element.name=All JSON
JSON_New_context_type_Extension_Element.name=New JSON
-
+JSON_Package_context_type_Extension_Element.name=New package.json
diff --git a/bundles/org.eclipse.wst.json.ui/plugin.xml b/bundles/org.eclipse.wst.json.ui/plugin.xml
index 2be5412a46..d59992a960 100644
--- a/bundles/org.eclipse.wst.json.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.json.ui/plugin.xml
@@ -280,6 +280,11 @@
class="org.eclipse.wst.json.ui.internal.templates.TemplateContextTypeJSON"
id="json_new">
</contextType>
+ <contextType
+ name="%JSON_Package_context_type_Extension_Element.name"
+ class="org.eclipse.wst.json.ui.internal.templates.TemplateContextTypeJSON"
+ id="json_package">
+ </contextType>
<include
file="templates/jsondefault-templates.xml"
translations="$nl$/templates/jsondefault-templates.properties">
@@ -683,6 +688,15 @@
id="org.eclipse.wst.json.core.jsonsource">
</contentType>
</proposalComputer>
+ <proposalComputer
+ activate="false"
+ categoryId="org.eclipse.wst.json.ui.proposalCategory.jsonTemplates"
+ class="org.eclipse.wst.json.ui.internal.contentassist.JSONPackageTemplatesCompletionProposalComputer"
+ id="org.eclipse.wst.json.ui.proposalComputer.jsonPackageTemplates">
+ <contentType
+ id="org.eclipse.wst.json.npm.core.npmsource">
+ </contentType>
+ </proposalComputer>
</extension>
<extension
point="org.eclipse.wst.sse.ui.completionProposalCategoriesConfiguration">
diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIPlugin.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIPlugin.java
index a3962e6e06..61af250c13 100644
--- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIPlugin.java
+++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIPlugin.java
@@ -1,38 +1,38 @@
-/**
+/**
* Copyright (c) 2013-2016 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
- */
-package org.eclipse.wst.json.ui.internal;
-
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
+ */
+package org.eclipse.wst.json.ui.internal;
+
import java.io.IOException;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wst.json.ui.internal.preferences.JSONUIPreferenceNames;
import org.eclipse.wst.json.ui.internal.templates.TemplateContextTypeIdsJSON;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class JSONUIPlugin extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.wst.json.ui"; //$NON-NLS-1$
-
- // The shared instance
- private static JSONUIPlugin plugin;
-
- /**
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class JSONUIPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.wst.json.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static JSONUIPlugin plugin;
+
+ /**
* The template store for the json ui.
*/
private TemplateStore fTemplateStore;
@@ -43,48 +43,48 @@ public class JSONUIPlugin extends AbstractUIPlugin {
private ContextTypeRegistry fContextTypeRegistry;
/**
- * The constructor
- */
- public JSONUIPlugin() {
- }
-
- /*
- * (non-Javadoc)
+ * The constructor
+ */
+ public JSONUIPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
*
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
- */
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
@Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
*
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
- * )
- */
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
@Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
*
- * @return the shared instance
- */
- public static JSONUIPlugin getDefault() {
- return plugin;
- }
-
+ * @return the shared instance
+ */
+ public static JSONUIPlugin getDefault() {
+ return plugin;
+ }
+
/**
- * Returns the template store for the css editor templates.
+ * Returns the template store for the JSON editor templates.
*
* @return the template store for the JSON editor templates
*/
@@ -112,10 +112,10 @@ public class JSONUIPlugin extends AbstractUIPlugin {
ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
registry.addContextType(TemplateContextTypeIdsJSON.ALL);
registry.addContextType(TemplateContextTypeIdsJSON.NEW);
-
+ registry.addContextType(TemplateContextTypeIdsJSON.PACKAGE);
fContextTypeRegistry = registry;
}
return fContextTypeRegistry;
}
-}
+}
diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONPackageTemplatesCompletionProposalComputer.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONPackageTemplatesCompletionProposalComputer.java
new file mode 100644
index 0000000000..4b2d4d5675
--- /dev/null
+++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONPackageTemplatesCompletionProposalComputer.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.json.ui.internal.contentassist;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.wst.json.ui.internal.templates.TemplateContextTypeIdsJSON;
+import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
+import org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer;
+
+/**
+ * <p>Completion computer for JSON templates</p>
+ */
+public class JSONPackageTemplatesCompletionProposalComputer implements ICompletionProposalComputer {
+ /** <p>The template processor used to create the proposals</p> */
+ private JSONTemplateCompletionProcessor fTemplateProcessor = null;
+
+ /**
+ * <p>Create the computer</p>
+ */
+ public JSONPackageTemplatesCompletionProposalComputer() {
+ fTemplateProcessor = new JSONTemplateCompletionProcessor();
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public List computeCompletionProposals(
+ CompletionProposalInvocationContext context,
+ IProgressMonitor monitor) {
+ List proposals = new ArrayList();
+ proposals.addAll(getTemplates(TemplateContextTypeIdsJSON.PACKAGE, context));
+ return proposals;
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public List computeContextInformation(
+ CompletionProposalInvocationContext context,
+ IProgressMonitor monitor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#getErrorMessage()
+ */
+ public String getErrorMessage() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#sessionStarted()
+ */
+ public void sessionStarted() {
+ //default is to do nothing
+ }
+
+ /**
+ * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#sessionEnded()
+ */
+ public void sessionEnded() {
+ //default is to do nothing
+ }
+
+ /**
+ * <p>Gets template proposals for the given template and proposal contexts</p>
+ *
+ * @param templateContext the template context
+ * @param context the proposal context
+ * @return {@link List} of template proposals for the given contexts
+ */
+ private List getTemplates(String templateContext,
+ CompletionProposalInvocationContext context) {
+ fTemplateProcessor.setContextType(templateContext);
+ ICompletionProposal[] proposals = fTemplateProcessor.computeCompletionProposals(
+ context.getViewer(), context.getInvocationOffset());
+ return Arrays.asList(proposals);
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeIdsJSON.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeIdsJSON.java
index 77df1f396b..97165a1a39 100644
--- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeIdsJSON.java
+++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeIdsJSON.java
@@ -17,4 +17,6 @@ public class TemplateContextTypeIdsJSON {
public static final String ALL = "json_all"; //$NON-NLS-1$
public static final String NEW = "json_new"; //$NON-NLS-1$
+
+ public static final String PACKAGE = "json_package"; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml b/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml
index 4794e7651e..b164571347 100644
--- a/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml
+++ b/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml
@@ -20,7 +20,7 @@
<template name="%Templates.newpair.name" description="%Templates.newpair.desc" id="org.eclipse.wst.json.ui.internal.templates.newpair"
context="json_all" enabled="true">"${key}": "${value}"</template>
<template name="%Templates.packagejson.name" description="%Templates.packagejson.desc" id="org.eclipse.wst.json.ui.internal.templates.packagejson"
- context="json_all" enabled="true">{
+ context="json_package" enabled="true">{
"name": "",
"version": "1.0.0",
"description": "",

Back to the top