diff options
author | Snjezana Peco | 2016-05-05 14:58:25 +0000 |
---|---|---|
committer | Nitin Dahyabhai | 2016-05-12 00:46:59 +0000 |
commit | 37ca115c4f1a06feec60ae5f11b9788cbff8cfac (patch) | |
tree | 89f1533d717a7e1807555c1efaa9347dbd53969b | |
parent | 4565f75522eecb3c4d2cda39dafb0c5c6bcb0600 (diff) | |
download | webtools.sourceediting-37ca115c4f1a06feec60ae5f11b9788cbff8cfac.tar.gz webtools.sourceediting-37ca115c4f1a06feec60ae5f11b9788cbff8cfac.tar.xz webtools.sourceediting-37ca115c4f1a06feec60ae5f11b9788cbff8cfac.zip |
Bug 487377 - JSON Preference page throws exceptions
Change-Id: I270b1881adf6a9e975c8efa099c3c4719a6d0d82
Signed-off-by: Snjezana Peco <snjeza.peco@gmail.com>
18 files changed, 936 insertions, 407 deletions
diff --git a/bundles/org.eclipse.wst.json.ui/icons/full/obj16/tag-template.gif b/bundles/org.eclipse.wst.json.ui/icons/full/obj16/tag-template.gif Binary files differnew file mode 100644 index 0000000000..5d1f81b6d4 --- /dev/null +++ b/bundles/org.eclipse.wst.json.ui/icons/full/obj16/tag-template.gif diff --git a/bundles/org.eclipse.wst.json.ui/plugin.properties b/bundles/org.eclipse.wst.json.ui/plugin.properties index 179a21d7a8..1df7d33a91 100644 --- a/bundles/org.eclipse.wst.json.ui/plugin.properties +++ b/bundles/org.eclipse.wst.json.ui/plugin.properties @@ -37,3 +37,7 @@ JSON_Editor.name=JSON Editor # content assist proposalCategory.json=JSON Proposals proposalCategory.jsonTemplates=JSON Template Proposals + +All_JSON_context_type_Extension_Element.name=All JSON +JSON_New_context_type_Extension_Element.name=New JSON + diff --git a/bundles/org.eclipse.wst.json.ui/plugin.xml b/bundles/org.eclipse.wst.json.ui/plugin.xml index 91f74c74dd..2be5412a46 100644 --- a/bundles/org.eclipse.wst.json.ui/plugin.xml +++ b/bundles/org.eclipse.wst.json.ui/plugin.xml @@ -119,7 +119,6 @@ id="org.eclipse.wst.sse.ui.preferences.json.contentassist"> <keywordReference id="org.eclipse.wst.json.ui.contentassist"/> </page> - <!-- <page name="%JSON_Templates.name" category="org.eclipse.wst.sse.ui.preferences.json.source" @@ -127,7 +126,6 @@ id="org.eclipse.wst.sse.ui.preferences.json.templates"> <keywordReference id="org.eclipse.wst.json.ui.templates"/> </page> - --> <page name="%JSON_Syntax_Coloring" category="org.eclipse.wst.sse.ui.preferences.json.source" @@ -283,7 +281,7 @@ id="json_new"> </contextType> <include - file="templates/jsondefault-templates.json" + file="templates/jsondefault-templates.xml" translations="$nl$/templates/jsondefault-templates.properties"> </include> </extension> diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/contentassist/AbstractJSONCompletionProposalComputer.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/contentassist/AbstractJSONCompletionProposalComputer.java index 85cd96c933..24b02a5804 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/contentassist/AbstractJSONCompletionProposalComputer.java +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/contentassist/AbstractJSONCompletionProposalComputer.java @@ -71,7 +71,7 @@ public abstract class AbstractJSONCompletionProposalComputer implements node); // Fix completion region in case of JSON_OBJECT_CLOSE - if (completionRegion.getType() == JSONRegionContexts.JSON_OBJECT_CLOSE && documentPosition > 0) { + if (completionRegion != null && completionRegion.getType() == JSONRegionContexts.JSON_OBJECT_CLOSE && documentPosition > 0) { completionRegion = getCompletionRegion(documentPosition - 1, node); } diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java index 807e33324e..48f22ab811 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java @@ -1,94 +1,94 @@ -/** - * Copyright (c) 2013-2014 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; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.osgi.util.NLS; - -/** - * Messages for JSON UI Plugin. - * - */ -public class JSONUIMessages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.wst.json.ui.internal.JSONUIMessages";//$NON-NLS-1$ - - private static ResourceBundle fResourceBundle; - - // Validation - public static String Not_an_integer; - public static String Missing_integer; -
- // Outline - public static String refreshoutline_0; - public static String SortAction_0; - - // Syntax color preferences page - public static String Sample_JSON_doc; - public static String SyntaxColoringPage_0; - public static String SyntaxColoringPage_2; - public static String SyntaxColoringPage_3; - public static String SyntaxColoringPage_4; - public static String SyntaxColoringPage_5; - public static String SyntaxColoringPage_6; - public static String CURLY_BRACE_UI_; - public static String COLON_UI_; - public static String COMMA_UI_; - public static String NORMAL_UI_; - public static String OBJECT_KEY_UI_; - public static String VALUE_BOOLEAN_UI_; - public static String VALUE_NULL_UI_; - public static String VALUE_NUMBER_UI_; - public static String VALUE_STRING_UI_; - public static String COMMENT_UI_; -
- // Validation preferences page - public static String SyntaxValidation_files; - public static String SyntaxValidation_files_label; - public static String Severity_error; - public static String Severity_warning; - public static String Severity_ignore; - public static String Missing_start_object; - public static String Missing_end_object; - public static String Missing_start_array; - public static String Missing_end_array; -
- // Preferences - public static String EmptyFilePreferencePage_0; - public static String EncodingSettings_0; - public static String EncodingSettings_1; -
- // JSONFilesPreferencePage preferences - public static String Creating_files; - public static String Encoding_desc; - public static String Encoding; - public static String JSONFilesPreferencePage_ExtensionLabel; - public static String JSONFilesPreferencePage_ExtensionError; -
- // JSONContentAssistPreferencePage - public static String JSONContentAssistPreferencePage_Auto_Activation_UI_; - public static String Automatically_make_suggest_UI_; - public static String Auto_Activation_Delay; - public static String Prompt_when_these_characte_UI_; - public static String Suggestion_Strategy; - public static String Suggestion_Strategy_Lax; - public static String Suggestion_Strategy_Strict; - public static String Group_label_Insertion; - public static String Insert_single_proposals; - public static String JSONContentAssistPreferencePage_Cycling_UI_; -
- // Content assist - public static String Content_Assist_not_availab_UI_; +/**
+ * 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;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages for JSON UI Plugin.
+ *
+ */
+public class JSONUIMessages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.wst.json.ui.internal.JSONUIMessages";//$NON-NLS-1$
+
+ private static ResourceBundle fResourceBundle;
+
+ // Validation
+ public static String Not_an_integer;
+ public static String Missing_integer;
+
+ // Outline
+ public static String refreshoutline_0;
+ public static String SortAction_0;
+
+ // Syntax color preferences page
+ public static String Sample_JSON_doc;
+ public static String SyntaxColoringPage_0;
+ public static String SyntaxColoringPage_2;
+ public static String SyntaxColoringPage_3;
+ public static String SyntaxColoringPage_4;
+ public static String SyntaxColoringPage_5;
+ public static String SyntaxColoringPage_6;
+ public static String CURLY_BRACE_UI_;
+ public static String COLON_UI_;
+ public static String COMMA_UI_;
+ public static String NORMAL_UI_;
+ public static String OBJECT_KEY_UI_;
+ public static String VALUE_BOOLEAN_UI_;
+ public static String VALUE_NULL_UI_;
+ public static String VALUE_NUMBER_UI_;
+ public static String VALUE_STRING_UI_;
+ public static String COMMENT_UI_;
+
+ // Validation preferences page
+ public static String SyntaxValidation_files;
+ public static String SyntaxValidation_files_label;
+ public static String Severity_error;
+ public static String Severity_warning;
+ public static String Severity_ignore;
+ public static String Missing_start_object;
+ public static String Missing_end_object;
+ public static String Missing_start_array;
+ public static String Missing_end_array;
+
+ // Preferences
+ public static String EmptyFilePreferencePage_0;
+ public static String EncodingSettings_0;
+ public static String EncodingSettings_1;
+
+ // JSONFilesPreferencePage preferences
+ public static String Creating_files;
+ public static String Encoding_desc;
+ public static String Encoding;
+ public static String JSONFilesPreferencePage_ExtensionLabel;
+ public static String JSONFilesPreferencePage_ExtensionError;
+
+ // JSONContentAssistPreferencePage
+ public static String JSONContentAssistPreferencePage_Auto_Activation_UI_;
+ public static String Automatically_make_suggest_UI_;
+ public static String Auto_Activation_Delay;
+ public static String Prompt_when_these_characte_UI_;
+ public static String Suggestion_Strategy;
+ public static String Suggestion_Strategy_Lax;
+ public static String Suggestion_Strategy_Strict;
+ public static String Group_label_Insertion;
+ public static String Insert_single_proposals;
+ public static String JSONContentAssistPreferencePage_Cycling_UI_;
+
+ // Content assist
+ public static String Content_Assist_not_availab_UI_;
public static String _UI_STRUCTURED_TEXT_EDITOR_PREFS_LINK;
public static String Formatting_UI_;
@@ -100,25 +100,26 @@ public class JSONUIMessages extends NLS { public static String PrefsLabel_WrappingWithoutAttr;
public static String PrefsLabel_WrappingInsertLineBreak;
public static String PrefsLabel_SelectorWhitespace;
- - - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, JSONUIMessages.class); - } - - private JSONUIMessages() { - // cannot create new instance - } - - public static ResourceBundle getResourceBundle() { - try { - if (fResourceBundle == null) { - fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME); - } - } catch (MissingResourceException x) { - fResourceBundle = null; - } - return fResourceBundle; - } -} +
+ public static String Creating_files_encoding;
+
+ static {
+ // load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, JSONUIMessages.class);
+ }
+
+ private JSONUIMessages() {
+ // cannot create new instance
+ }
+
+ public static ResourceBundle getResourceBundle() {
+ try {
+ if (fResourceBundle == null) {
+ fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
+ }
+ } catch (MissingResourceException x) {
+ fResourceBundle = null;
+ }
+ return fResourceBundle;
+ }
+}
diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties index 28343e73c2..28ad11ad37 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties @@ -1,67 +1,69 @@ -# Outline -refreshoutline_0=Refreshing Outline -SortAction_0=Sort - -# Preferences - -## Syntax Coloring preferences page -Sample_JSON_doc={\n\t// Here a simple JSON file\n\t"object": {},\n\t"array": [\n\t\t1,\n\t\t2,\n\t\t3],\n\t"boolean": true,\n\t"null": null,\n\t\"number": 123,\n\t"object": {\n\t\t"a": "b",\n\t\t"c": "d"\n\t},\n\t"string": "Hello World"\n} -SyntaxColoringPage_0=S&yntax Element: -SyntaxColoringPage_2=Enable -SyntaxColoringPage_3=&Bold -SyntaxColoringPage_4=&Italic -SyntaxColoringPage_5=&Strikethrough -SyntaxColoringPage_6=&Underline -CURLY_BRACE_UI_=Curly -COLON_UI_=Colon -COMMA_UI_=Comma -NORMAL_UI_=Normal -OBJECT_KEY_UI_=Object key -VALUE_BOOLEAN_UI_=Boolean value -VALUE_NULL_UI_=Null value -VALUE_NUMBER_UI_=Number value -VALUE_STRING_UI_=String value -COMMENT_UI_=Comment - -## Validation preferences page -SyntaxValidation_files=&Enable syntax validation -SyntaxValidation_files_label=Errors/Warnings -Severity_error=Error -Severity_warning=Warning -Severity_ignore=Ignore -Missing_start_object=Missing start object -Missing_end_object=Missing end object -Missing_start_array=Missing start array -Missing_end_array=Missing end array - -#EmptyFilePreferencePage -EmptyFilePreferencePage_0=Expand the tree to edit preferences for a specific feature. -# JSONFilesPreferencePage -Creating_files=Creating files -EncodingSettings_0=IANA: -EncodingSettings_1=Encoding: -Encoding_desc=The following encoding will apply: -Encoding=En&coding: -JSONFilesPreferencePage_ExtensionLabel=Add this &suffix (if not specified): -JSONFilesPreferencePage_ExtensionError=Suffix must be one of the following {0} - -# Validation -Not_an_integer=''{0}'' is not a positive integer. -Missing_integer=A positive integer must be specified. - -# JSONContentAssistPreferencePage -JSONContentAssistPreferencePage_Auto_Activation_UI_=Auto Activation -JSONContentAssistPreferencePage_Cycling_UI_=Cycling -Automatically_make_suggest_UI_=Automatically ma&ke suggestions -Auto_Activation_Delay=Auto activation dela&y (ms): -Prompt_when_these_characte_UI_=P&rompt when these characters are inserted: -Suggestion_Strategy=&Suggestion strategy: -Suggestion_Strategy_Lax=Lax -Suggestion_Strategy_Strict=Strict -Group_label_Insertion=Insertion -Insert_single_proposals=&Insert single proposals automatically - -# Content Assist +# Outline
+refreshoutline_0=Refreshing Outline
+SortAction_0=Sort
+
+# Preferences
+
+## Syntax Coloring preferences page
+Sample_JSON_doc={\n\t// Here a simple JSON file\n\t"object": {},\n\t"array": [\n\t\t1,\n\t\t2,\n\t\t3],\n\t"boolean": true,\n\t"null": null,\n\t\"number": 123,\n\t"object": {\n\t\t"a": "b",\n\t\t"c": "d"\n\t},\n\t"string": "Hello World"\n}
+SyntaxColoringPage_0=S&yntax Element:
+SyntaxColoringPage_2=Enable
+SyntaxColoringPage_3=&Bold
+SyntaxColoringPage_4=&Italic
+SyntaxColoringPage_5=&Strikethrough
+SyntaxColoringPage_6=&Underline
+CURLY_BRACE_UI_=Curly
+COLON_UI_=Colon
+COMMA_UI_=Comma
+NORMAL_UI_=Normal
+OBJECT_KEY_UI_=Object key
+VALUE_BOOLEAN_UI_=Boolean value
+VALUE_NULL_UI_=Null value
+VALUE_NUMBER_UI_=Number value
+VALUE_STRING_UI_=String value
+COMMENT_UI_=Comment
+
+## Validation preferences page
+SyntaxValidation_files=&Enable syntax validation
+SyntaxValidation_files_label=Errors/Warnings
+Severity_error=Error
+Severity_warning=Warning
+Severity_ignore=Ignore
+Missing_start_object=Missing start object
+Missing_end_object=Missing end object
+Missing_start_array=Missing start array
+Missing_end_array=Missing end array
+
+#EmptyFilePreferencePage
+EmptyFilePreferencePage_0=Expand the tree to edit preferences for a specific feature.
+# JSONFilesPreferencePage
+Creating_files=Creating files
+EncodingSettings_0=IANA:
+EncodingSettings_1=Encoding:
+Encoding_desc=The following encoding will apply:
+Encoding=En&coding:
+JSONFilesPreferencePage_ExtensionLabel=Add this &suffix (if not specified):
+JSONFilesPreferencePage_ExtensionError=Suffix must be one of the following {0}
+
+Creating_files_encoding=Creating files encoding preference
+
+# Validation
+Not_an_integer=''{0}'' is not a positive integer.
+Missing_integer=A positive integer must be specified.
+
+# JSONContentAssistPreferencePage
+JSONContentAssistPreferencePage_Auto_Activation_UI_=Auto Activation
+JSONContentAssistPreferencePage_Cycling_UI_=Cycling
+Automatically_make_suggest_UI_=Automatically ma&ke suggestions
+Auto_Activation_Delay=Auto activation dela&y (ms):
+Prompt_when_these_characte_UI_=P&rompt when these characters are inserted:
+Suggestion_Strategy=&Suggestion strategy:
+Suggestion_Strategy_Lax=Lax
+Suggestion_Strategy_Strict=Strict
+Group_label_Insertion=Insertion
+Insert_single_proposals=&Insert single proposals automatically
+
+# Content Assist
Content_Assist_not_availab_UI_=Content Assist not available at the current location
_UI_STRUCTURED_TEXT_EDITOR_PREFS_LINK=JSON editing preferences. Note that some preferences may be set on the <a>{0}</a> preference page.
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 4d07058444..a3962e6e06 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,66 +1,121 @@ -/**
- * Copyright (c) 2013-2014 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;
+/** + * 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; + +import java.io.IOException;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-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.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.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; + + /** + * The template store for the json ui.
+ */
+ private TemplateStore fTemplateStore;
/**
- * The constructor
+ * The template context type registry for json ui.
*/
- public JSONUIPlugin() {
- }
+ private ContextTypeRegistry fContextTypeRegistry;
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
+ /**
+ * The constructor + */ + public JSONUIPlugin() { + } + + /* + * (non-Javadoc) + *
+ * @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) + *
+ * @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 + *
+ * @return the shared instance + */ + public static JSONUIPlugin getDefault() { + return plugin; + } + + /**
+ * Returns the template store for the css editor templates.
+ *
+ * @return the template store for the JSON editor templates
*/
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
+ public TemplateStore getTemplateStore() {
+ if (fTemplateStore == null) {
+ fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(),
+ JSONUIPreferenceNames.TEMPLATES_KEY);
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
- * )
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
+ try {
+ fTemplateStore.load();
+ } catch (IOException e) {
+ Logger.logException(e);
+ }
+ }
+ return fTemplateStore;
}
/**
- * Returns the shared instance
- *
- * @return the shared instance
+ * Returns the template context type registry for the JSON plugin.
+ *
+ * @return the template context type registry for the JSON plugin
*/
- public static JSONUIPlugin getDefault() {
- return plugin;
- }
+ public ContextTypeRegistry getTemplateContextRegistry() {
+ if (fContextTypeRegistry == null) {
+ ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
+ registry.addContextType(TemplateContextTypeIdsJSON.ALL);
+ registry.addContextType(TemplateContextTypeIdsJSON.NEW);
+
+ fContextTypeRegistry = registry;
+ }
-}
+ return fContextTypeRegistry;
+ }
+} diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplateCompletionProcessor.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplateCompletionProcessor.java new file mode 100644 index 0000000000..e585713e35 --- /dev/null +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplateCompletionProcessor.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2004, 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 org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.templates.ContextTypeRegistry; +import org.eclipse.jface.text.templates.Template; +import org.eclipse.jface.text.templates.TemplateCompletionProcessor; +import org.eclipse.jface.text.templates.TemplateContextType; +import org.eclipse.jface.text.templates.persistence.TemplateStore; +import org.eclipse.swt.graphics.Image; +import org.eclipse.wst.json.ui.internal.JSONUIPlugin; +import org.eclipse.wst.json.ui.internal.editor.JSONEditorPluginImageHelper; +import org.eclipse.wst.json.ui.internal.editor.JSONEditorPluginImages; + + +/** + * Completion processor for JSON Templates. Most of the work is already done + * by the JSON Content Assist processor, so by the time the + * JSONTemplateCompletionProcessor is asked for content assist proposals, the + * JSON content assist processor has already set the context type for + * templates. + */ +class JSONTemplateCompletionProcessor extends TemplateCompletionProcessor { + private String fContextTypeId = null; + + protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { + TemplateContextType type = null; + + ContextTypeRegistry registry = getTemplateContextRegistry(); + if (registry != null) + type = registry.getContextType(fContextTypeId); + + return type; + } + + protected Image getImage(Template template) { + // just return the same image for now + return JSONEditorPluginImageHelper.getInstance().getImage(JSONEditorPluginImages.IMG_OBJ_TEMPLATE); + } + + private ContextTypeRegistry getTemplateContextRegistry() { + return JSONUIPlugin.getDefault().getTemplateContextRegistry(); + } + + protected Template[] getTemplates(String contextTypeId) { + Template templates[] = null; + + TemplateStore store = getTemplateStore(); + if (store != null) + templates = store.getTemplates(contextTypeId); + + return templates; + } + + private TemplateStore getTemplateStore() { + return JSONUIPlugin.getDefault().getTemplateStore(); + } + + void setContextType(String contextTypeId) { + fContextTypeId = contextTypeId; + } +} diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplatesCompletionProposalComputer.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplatesCompletionProposalComputer.java index 2580c48afc..56445c8ad4 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplatesCompletionProposalComputer.java +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/contentassist/JSONTemplatesCompletionProposalComputer.java @@ -1,18 +1,107 @@ +/*******************************************************************************
+ * 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;
+import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
+
/**
- * Copyright (c) 2013-2014 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
+ * <p>Completion computer for JSON templates</p>
*/
-package org.eclipse.wst.json.ui.internal.contentassist;
+public class JSONTemplatesCompletionProposalComputer implements ICompletionProposalComputer {
+ /** <p>The template processor used to create the proposals</p> */
+ private JSONTemplateCompletionProcessor fTemplateProcessor = null;
+
+ /**
+ * <p>Create the computer</p>
+ */
+ public JSONTemplatesCompletionProposalComputer() {
+ 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();
+
+ boolean isEmptyDocument =
+ ContentAssistUtils.isViewerEmpty(context.getViewer());
+ if (isEmptyDocument) {
+ proposals.addAll(getTemplates(TemplateContextTypeIdsJSON.NEW, context));
+ }
+ proposals.addAll(getTemplates(TemplateContextTypeIdsJSON.ALL, 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;
+ }
-import org.eclipse.wst.json.ui.contentassist.DefaultJSONCompletionProposalComputer;
+ /**
+ * @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
+ }
+
-public class JSONTemplatesCompletionProposalComputer extends
- DefaultJSONCompletionProposalComputer {
+ /**
+ * <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/editor/JSONEditorPluginImages.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONEditorPluginImages.java index 330adb33f9..4a09916645 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONEditorPluginImages.java +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONEditorPluginImages.java @@ -1,24 +1,27 @@ -/**
- * Copyright (c) 2015, 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.editor;
+/** + * Copyright (c) 2015, 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.editor; + +import org.eclipse.json.schema.JSONSchemaType;
-public class JSONEditorPluginImages {
-
- public static final String IMG_OBJ_OBJECT = "icons/full/obj16/json-object.png";
- public static final String IMG_OBJ_ARRAY = "icons/full/obj16/json-array.png";
- public static final String IMG_OBJ_VALUE_BOOLEAN = "icons/full/obj16/json-boolean.png";
- public static final String IMG_OBJ_VALUE_NUMBER = "icons/full/obj16/json-number.png";
- public static final String IMG_OBJ_VALUE_NULL = "icons/full/obj16/json-null.png";
- public static final String IMG_OBJ_VALUE_STRING = "icons/full/obj16/json-string.png";
+public class JSONEditorPluginImages { + + public static final String IMG_OBJ_OBJECT = "icons/full/obj16/json-object.png"; + public static final String IMG_OBJ_ARRAY = "icons/full/obj16/json-array.png"; + public static final String IMG_OBJ_VALUE_BOOLEAN = "icons/full/obj16/json-boolean.png"; + public static final String IMG_OBJ_VALUE_NUMBER = "icons/full/obj16/json-number.png"; + public static final String IMG_OBJ_VALUE_NULL = "icons/full/obj16/json-null.png"; + public static final String IMG_OBJ_VALUE_STRING = "icons/full/obj16/json-string.png"; + public static final String IMG_OBJ_TEMPLATE = "icons/full/obj16/tag-template.gif"; //$NON-NLS-1$
+ public static final String IMG_OBJ_SORT = "icons/full/obj16/sort.gif"; - public static final String IMG_OBJ_SORT = "icons/full/obj16/sort.gif";
-
-}
+ +} diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONTemplatePreferencePage.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONTemplatePreferencePage.java new file mode 100644 index 0000000000..e0c613d722 --- /dev/null +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONTemplatePreferencePage.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2004, 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.preferences; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.jface.text.templates.ContextTypeRegistry; +import org.eclipse.jface.text.templates.Template; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; +import org.eclipse.wst.json.core.contenttype.ContentTypeIdForJSON; +import org.eclipse.wst.json.ui.StructuredTextViewerConfigurationJSON; +import org.eclipse.wst.json.ui.internal.JSONUIPlugin; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; +import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; +import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; + +/** + * Preference page for JSON templates + */ +public class JSONTemplatePreferencePage extends TemplatePreferencePage { + + class JSONEditTemplateDialog extends EditTemplateDialog { + public JSONEditTemplateDialog(Shell parent, Template template, boolean edit, boolean isNameModifiable, ContextTypeRegistry registry) { + super(parent, template, edit, isNameModifiable, registry); + } + + @Override + protected SourceViewer createViewer(Composite parent) { SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { + StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationJSON(); + + @Override + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return baseConfiguration.getConfiguredContentTypes(sourceViewer); + } + + @Override + public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { + return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); + } + + @Override + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + assistant.enableAutoActivation(true); + assistant.enableAutoInsert(true); + assistant.setContentAssistProcessor(getTemplateProcessor(), IDocument.DEFAULT_CONTENT_TYPE); + return assistant; + } + }; + return doCreateViewer(parent, sourceViewerConfiguration); +} + } + + public JSONTemplatePreferencePage() { + JSONUIPlugin jsonUIPlugin = JSONUIPlugin.getDefault(); + + setPreferenceStore(jsonUIPlugin.getPreferenceStore()); + setTemplateStore(jsonUIPlugin.getTemplateStore()); + setContextTypeRegistry(jsonUIPlugin.getTemplateContextRegistry()); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.IPreferencePage#performOk() + */ + @Override + public boolean performOk() { + boolean ok = super.performOk(); + JSONUIPlugin.getDefault().savePluginPreferences(); + return ok; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#isShowFormatterSetting() + */ + @Override + protected boolean isShowFormatterSetting() { + // template formatting has not been implemented + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite ancestor) { + Control c = super.createContents(ancestor); + // PlatformUI.getWorkbench().getHelpSystem().setHelp(c, + // IHelpContextIds.CSS_PREFWEBX_TEMPLATES_HELPID); + return c; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#createViewer(org.eclipse.swt.widgets.Composite) + */ + @Override + protected SourceViewer createViewer(Composite parent) { + SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { + StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationJSON(); + + @Override + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return baseConfiguration.getConfiguredContentTypes(sourceViewer); + } + + @Override + public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { + return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); + } + }; + return doCreateViewer(parent, sourceViewerConfiguration); + } + + SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) { + SourceViewer viewer = null; + String contentTypeID = ContentTypeIdForJSON.ContentTypeID_JSON; + viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ + IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID); + IDocument document = scratchModel.getStructuredDocument(); + viewer.configure(viewerConfiguration); + viewer.setDocument(document); + return viewer; + } + + /** + * Creates the edit dialog. Subclasses may override this method to provide + * a custom dialog. + * + * @param template + * the template being edited + * @param edit + * whether the dialog should be editable + * @param isNameModifiable + * whether the template name may be modified + * @return the created or modified template, or <code>null</code> if the + * edition failed + * @since 3.1 + */ + @Override + protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) { + EditTemplateDialog dialog = new JSONEditTemplateDialog(getShell(), template, edit, isNameModifiable, getContextTypeRegistry()); + if (dialog.open() == Window.OK) { + return dialog.getTemplate(); + } + return null; + } +} diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java index 1850206cb2..51db2bc88a 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java @@ -1,15 +1,15 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 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 - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference + * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference * Angelo Zerr <angelo.zerr@gmail.com> - copied from org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceInitializer - * modified in order to process JSON Objects. + * modified in order to process JSON Objects. *******************************************************************************/ package org.eclipse.wst.json.ui.internal.preferences; @@ -28,10 +28,11 @@ public class JSONUIPreferenceInitializer extends AbstractPreferenceInitializer { /* * (non-Javadoc) - * + * * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer# * initializeDefaultPreferences() */ + @Override public void initializeDefaultPreferences() { IPreferenceStore store = JSONUIPlugin.getDefault().getPreferenceStore(); ColorRegistry registry = PlatformUI.getWorkbench().getThemeManager() diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java index 2b131f131f..3530292327 100644 --- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java @@ -1,136 +1,145 @@ -/*******************************************************************************
- * Copyright (c) 2005, 2012 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
- * Angelo Zerr <angelo.zerr@gmail.com> - copied from org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames
- * modified in order to process JSON Objects.
- *******************************************************************************/
-package org.eclipse.wst.json.ui.internal.preferences;
+/******************************************************************************* + * Copyright (c) 2005, 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 + * Angelo Zerr <angelo.zerr@gmail.com> - copied from org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames + * modified in order to process JSON Objects.
+ *******************************************************************************/ +package org.eclipse.wst.json.ui.internal.preferences; + -public class JSONUIPreferenceNames {
-
- /**
- * <p>
- * preference key used for saving which categories should not display on the
- * default page
- * </p>
- *
- * <p>
- * Value is of type {@link String} consisting of
- * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s
- * separated by the null character (<tt>\0</tt>), ordered is ignored
- * </p>
- */
- public static final String CONTENT_ASSIST_DO_NOT_DISPLAY_ON_DEFAULT_PAGE = "json_content_assist_display_on_default_page"; //$NON-NLS-1$
-
- /**
- * <p>
- * preference key used for saving which categories should not display on
- * their own page
- * </p>
- *
- * <p>
- * Value is of type {@link String} consisting of
- * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s
- * separated by the null character (<tt>\0</tt>), order is ignored
- * </p>
- */
- public static final String CONTENT_ASSIST_DO_NOT_DISPLAY_ON_OWN_PAGE = "json_content_assist_display_on_own_page"; //$NON-NLS-1$
-
- /**
- * <p>
- * preference key for saving the sort order of the categories when
- * displaying them on their own page
- * </p>
- *
- * <p>
- * Value is of type {@link String} consisting of
- * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s
- * separated by the null character (<tt>\0</tt>) in the desired sort order.
- * </p>
- */
- public static final String CONTENT_ASSIST_OWN_PAGE_SORT_ORDER = "json_content_assist_own_page_sort_order"; //$NON-NLS-1$
-
- /**
- * <p>
- * preference key for saving the sort order of the categories when
- * displaying them on the default page
- * </p>
- *
- * <p>
- * Value is of type {@link String} consisting of
- * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s
- * separated by the null character (<tt>\0</tt>) in the desired sort order.
- * </p>
- */
- public static final String CONTENT_ASSIST_DEFAULT_PAGE_SORT_ORDER = "json_content_assist_default_page_sort_order"; //$NON-NLS-1$
-
- public final static String SUGGESTION_STRATEGY_VALUE_LAX = "Lax"; //$NON-NLS-1$
- public final static String SUGGESTION_STRATEGY_VALUE_STRICT = "Strict"; //$NON-NLS-1$
-
- /**
- * A named preference that holds the characters that auto activate code
- * assist.
- * <p>
- * Value is of type <code>String</code>. All characters that trigger auto
- * code assist.
- * </p>
- */
- public static final String SUGGESTION_STRATEGY = getSuggestionStrategeyKey();
-
- private static String getSuggestionStrategeyKey() {
- return "suggestionStrategy";//$NON-NLS-1$
- }
-
- /**
- * A named preference that controls time before code assist gets auto
- * activated.
+public class JSONUIPreferenceNames { + + /** + * The key to store customized templates.
* <p>
* Value is of type <code>String</code>.
* </p>
*/
- public static final String AUTO_PROPOSE_DELAY = "autoProposeDelay";//$NON-NLS-1$
+ public static final String TEMPLATES_KEY = "org.eclipse.wst.json.ui.custom_templates"; //$NON-NLS-1$
/**
- * A named preference that controls if code assist gets auto activated.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String AUTO_PROPOSE = getAutoProposeKey();
-
- private static String getAutoProposeKey() {
- return "autoPropose";//$NON-NLS-1$
- }
-
- /**
- * A named preference that holds the characters that auto activate code
- * assist.
- * <p>
- * Value is of type <code>String</code>. All characters that trigger auto
- * code assist.
- * </p>
- */
- public static final String AUTO_PROPOSE_CODE = getAutoProposeCodeKey();
-
- private static String getAutoProposeCodeKey() {
- return "autoProposeCode";//$NON-NLS-1$
- }
-
- /**
- * <p>
- * preference key to store the option for auto insertion of single
- * suggestions
- * </p>
- * <p>
- * Value is of type <code>boolean</code>
- * </p>
- */
- public static final String INSERT_SINGLE_SUGGESTION = "insertSingleSuggestion"; //$NON-NLS-1$
-
-}
+ * <p> + * preference key used for saving which categories should not display on the + * default page + * </p> + *
+ * <p> + * Value is of type {@link String} consisting of + * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s + * separated by the null character (<tt>\0</tt>), ordered is ignored + * </p> + */ + public static final String CONTENT_ASSIST_DO_NOT_DISPLAY_ON_DEFAULT_PAGE = "json_content_assist_display_on_default_page"; //$NON-NLS-1$ + + /** + * <p> + * preference key used for saving which categories should not display on + * their own page + * </p> + *
+ * <p> + * Value is of type {@link String} consisting of + * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s + * separated by the null character (<tt>\0</tt>), order is ignored + * </p> + */ + public static final String CONTENT_ASSIST_DO_NOT_DISPLAY_ON_OWN_PAGE = "json_content_assist_display_on_own_page"; //$NON-NLS-1$ + + /** + * <p> + * preference key for saving the sort order of the categories when + * displaying them on their own page + * </p> + *
+ * <p> + * Value is of type {@link String} consisting of + * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s + * separated by the null character (<tt>\0</tt>) in the desired sort order. + * </p> + */ + public static final String CONTENT_ASSIST_OWN_PAGE_SORT_ORDER = "json_content_assist_own_page_sort_order"; //$NON-NLS-1$ + + /** + * <p> + * preference key for saving the sort order of the categories when + * displaying them on the default page + * </p> + *
+ * <p> + * Value is of type {@link String} consisting of + * <tt>org.eclipse.wst.sse.ui.completionProposal/proposalCategory/@id</tt>s + * separated by the null character (<tt>\0</tt>) in the desired sort order. + * </p> + */ + public static final String CONTENT_ASSIST_DEFAULT_PAGE_SORT_ORDER = "json_content_assist_default_page_sort_order"; //$NON-NLS-1$ + + public final static String SUGGESTION_STRATEGY_VALUE_LAX = "Lax"; //$NON-NLS-1$ + public final static String SUGGESTION_STRATEGY_VALUE_STRICT = "Strict"; //$NON-NLS-1$ + + /** + * A named preference that holds the characters that auto activate code + * assist. + * <p> + * Value is of type <code>String</code>. All characters that trigger auto + * code assist. + * </p> + */ + public static final String SUGGESTION_STRATEGY = getSuggestionStrategeyKey(); + + private static String getSuggestionStrategeyKey() { + return "suggestionStrategy";//$NON-NLS-1$ + } + + /** + * A named preference that controls time before code assist gets auto + * activated. + * <p> + * Value is of type <code>String</code>. + * </p> + */ + public static final String AUTO_PROPOSE_DELAY = "autoProposeDelay";//$NON-NLS-1$ + + /** + * A named preference that controls if code assist gets auto activated. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + */ + public static final String AUTO_PROPOSE = getAutoProposeKey(); + + private static String getAutoProposeKey() { + return "autoPropose";//$NON-NLS-1$ + } + + /** + * A named preference that holds the characters that auto activate code + * assist. + * <p> + * Value is of type <code>String</code>. All characters that trigger auto + * code assist. + * </p> + */ + public static final String AUTO_PROPOSE_CODE = getAutoProposeCodeKey(); + + private static String getAutoProposeCodeKey() { + return "autoProposeCode";//$NON-NLS-1$ + } + + /** + * <p> + * preference key to store the option for auto insertion of single + * suggestions + * </p> + * <p> + * Value is of type <code>boolean</code> + * </p> + */ + public static final String INSERT_SINGLE_SUGGESTION = "insertSingleSuggestion"; //$NON-NLS-1$ + +} diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/EncodingTemplateVariableResolverJSON.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/EncodingTemplateVariableResolverJSON.java new file mode 100644 index 0000000000..93d113e186 --- /dev/null +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/EncodingTemplateVariableResolverJSON.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.templates; + +import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver; +import org.eclipse.jface.text.templates.TemplateContext; +import org.eclipse.wst.json.core.JSONCorePlugin; +import org.eclipse.wst.json.ui.internal.JSONUIMessages; +import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; + + +public class EncodingTemplateVariableResolverJSON extends SimpleTemplateVariableResolver { + private static final String ENCODING_TYPE = getEncodingType(); + + private static String getEncodingType() { + return "encoding"; //$NON-NLS-1$ + } + + /** + * Creates a new encoding variable + */ + public EncodingTemplateVariableResolverJSON() { + super(ENCODING_TYPE, JSONUIMessages.Creating_files_encoding); + } + + @Override + protected String resolve(TemplateContext context) { + return JSONCorePlugin.getDefault().getPluginPreferences() + .getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); + } +} 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 new file mode 100644 index 0000000000..77df1f396b --- /dev/null +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeIdsJSON.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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.templates; + + +public class TemplateContextTypeIdsJSON { + + public static final String ALL = "json_all"; //$NON-NLS-1$ + + public static final String NEW = "json_new"; //$NON-NLS-1$ +} diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeJSON.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeJSON.java new file mode 100644 index 0000000000..1e0aba420c --- /dev/null +++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/templates/TemplateContextTypeJSON.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.templates; + +import org.eclipse.jface.text.templates.GlobalTemplateVariables; +import org.eclipse.jface.text.templates.TemplateContextType; + +/** + * Base class for JSON template context types. Templates of this context type + * apply to any place within JSON content type. + */ +public class TemplateContextTypeJSON extends TemplateContextType { + + public TemplateContextTypeJSON() { + super(); + addResolver(new GlobalTemplateVariables.Cursor()); + addResolver(new GlobalTemplateVariables.Date()); + addResolver(new GlobalTemplateVariables.Dollar()); + addResolver(new GlobalTemplateVariables.LineSelection()); + addResolver(new GlobalTemplateVariables.Time()); + addResolver(new GlobalTemplateVariables.User()); + addResolver(new GlobalTemplateVariables.WordSelection()); + addResolver(new GlobalTemplateVariables.Year()); + addResolver(new EncodingTemplateVariableResolverJSON()); + } +} diff --git a/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.properties b/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.properties index 40eaa60ab7..4ad39903ae 100644 --- a/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.properties +++ b/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2013 Angelo Zerr and others. +# Copyright (c) 2016 Angelo Zerr 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 @@ -8,5 +8,11 @@ # Contributors: # Angelo Zerr <angelo.zerr@gmail.com> - Initial API and implementation ############################################################################### -Templates.newobject.name=New Json object -Templates.newobject.desc=new Json object +Templates.newobject.name=object +Templates.newobject.desc=new JSON object +Templates.newarray.name=array +Templates.newarray.desc=new JSON array +Templates.newpair.name=pair +Templates.newpair.desc=new JSON pair +Templates.packagejson.name=packagejson +Templates.packagejson.desc=new package.json 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 7212ef9fa7..4794e7651e 100644 --- a/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml +++ b/bundles/org.eclipse.wst.json.ui/templates/jsondefault-templates.xml @@ -13,5 +13,25 @@ *******************************************************************************/ --> <templates> -<template name="%Templates.newobject.name" description="%Templates.newobject.desc" id="org.eclipse.wst.json.ui.internal.templates.newobject" context="json_new" enabled="true">{"${key}": ${value}}</template> +<template name="%Templates.newobject.name" description="%Templates.newobject.desc" id="org.eclipse.wst.json.ui.internal.templates.newobject" + context="json_all" enabled="true">{"${key}": "${value}"}</template> +<template name="%Templates.newarray.name" description="%Templates.newarray.desc" id="org.eclipse.wst.json.ui.internal.templates.newarray" + context="json_all" enabled="true">"${key}": [] </template> +<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">{ + "name": "", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": {}, + "keywords": [], + "author": "${user}", + "license": "EPL", + "dependencies": {}, + "devDependencies": {} +} +</template> + </templates> |