Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2014-10-29 23:34:17 +0000
committerTom Schindl2014-10-29 23:34:17 +0000
commitc27d2c29dd8be3fa81ff8a11af2226112fa360dd (patch)
tree4cfbfd73c28982edce943d7a55b9e19486608b98 /bundles/tooling/org.eclipse.fx.ide.l10n.ui/src
parente66678f7ae7bae5cfabe24b50b1380640fdbc640 (diff)
downloadorg.eclipse.efxclipse-c27d2c29dd8be3fa81ff8a11af2226112fa360dd.tar.gz
org.eclipse.efxclipse-c27d2c29dd8be3fa81ff8a11af2226112fa360dd.tar.xz
org.eclipse.efxclipse-c27d2c29dd8be3fa81ff8a11af2226112fa360dd.zip
Bug 449260 - Add DSL to easily author NLS-Files and generate accessor
classes
Diffstat (limited to 'bundles/tooling/org.eclipse.fx.ide.l10n.ui/src')
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/NLSDslUiModule.java37
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/contentassist/NLSDslProposalProvider.xtend12
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/edit/StringReplacementHandler.xtend44
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingCalculator.xtend22
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingConfiguration.xtend22
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/TokenToAttributeIdMapper.xtend18
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslDescriptionLabelProvider.xtend24
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslLabelProvider.xtend29
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/outline/NLSDslOutlineTreeProvider.xtend13
-rw-r--r--bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/quickfix/NLSDslQuickfixProvider.xtend26
10 files changed, 247 insertions, 0 deletions
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/NLSDslUiModule.java b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/NLSDslUiModule.java
new file mode 100644
index 000000000..ef5d17e80
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/NLSDslUiModule.java
@@ -0,0 +1,37 @@
+/*
+ * generated by Xtext
+ */
+package org.eclipse.fx.ide.l10n.ui;
+
+import org.eclipse.fx.ide.l10n.ui.highlighting.NLSHighlightingCalculator;
+import org.eclipse.fx.ide.l10n.ui.highlighting.NLSHighlightingConfiguration;
+import org.eclipse.fx.ide.l10n.ui.highlighting.TokenToAttributeIdMapper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
+
+import com.google.inject.Binder;
+import com.google.inject.name.Names;
+
+/**
+ * Use this class to register components to be used within the IDE.
+ */
+public class NLSDslUiModule extends org.eclipse.fx.ide.l10n.ui.AbstractNLSDslUiModule {
+ public NLSDslUiModule(AbstractUIPlugin plugin) {
+ super(plugin);
+ }
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+
+ binder.bindConstant().annotatedWith(Names.named(XtextEditor.KEY_BINDING_SCOPE))
+ .to("org.eclipse.fx.ide.l10n.ui.NLSEditorScope");
+ binder.bind(AbstractAntlrTokenToAttributeIdMapper.class).to(TokenToAttributeIdMapper.class);
+ binder.bind(IHighlightingConfiguration.class).to(NLSHighlightingConfiguration.class);
+ binder.bind(ISemanticHighlightingCalculator.class).to(NLSHighlightingCalculator.class);
+ }
+
+}
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/contentassist/NLSDslProposalProvider.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/contentassist/NLSDslProposalProvider.xtend
new file mode 100644
index 000000000..535e3fca5
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/contentassist/NLSDslProposalProvider.xtend
@@ -0,0 +1,12 @@
+/*
+ * generated by Xtext
+ */
+package org.eclipse.fx.ide.l10n.ui.contentassist
+
+import org.eclipse.fx.ide.l10n.ui.contentassist.AbstractNLSDslProposalProvider
+
+/**
+ * see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to customize content assistant
+ */
+class NLSDslProposalProvider extends AbstractNLSDslProposalProvider {
+}
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/edit/StringReplacementHandler.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/edit/StringReplacementHandler.xtend
new file mode 100644
index 000000000..f2353af1d
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/edit/StringReplacementHandler.xtend
@@ -0,0 +1,44 @@
+package org.eclipse.fx.ide.l10n.ui.edit
+
+import org.eclipse.core.commands.AbstractHandler
+import org.eclipse.core.commands.ExecutionEvent
+import org.eclipse.core.commands.ExecutionException
+import org.eclipse.xtext.ui.editor.utils.EditorUtils
+import org.eclipse.swt.widgets.Event
+import org.eclipse.swt.SWT
+
+abstract class StringReplacementHandler extends AbstractHandler {
+ static class LeftGuillemet extends org.eclipse.fx.ide.l10n.ui.edit.StringReplacementHandler {
+ new() {
+ super('\u00ab')
+ }
+ }
+
+ static class RightGuillemet extends org.eclipse.fx.ide.l10n.ui.edit.StringReplacementHandler {
+ new() {
+ super('\u00bb')
+ }
+ }
+
+ val char replacement;
+
+ new(char replacement) {
+ this.replacement = replacement
+ }
+
+ override execute(ExecutionEvent event) throws ExecutionException {
+ val editor = EditorUtils::getActiveXtextEditor(event)
+ if( editor == null ) {
+ return null
+ }
+
+ editor.internalSourceViewer.textWidget.notifyListeners(SWT::KeyDown,new Event => [
+ character = replacement
+ type = SWT::KeyDown
+ doit = true
+ ])
+
+ return null
+ }
+
+} \ No newline at end of file
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingCalculator.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingCalculator.xtend
new file mode 100644
index 000000000..51dfa93e8
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingCalculator.xtend
@@ -0,0 +1,22 @@
+package org.eclipse.fx.ide.l10n.ui.highlighting
+
+import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator
+import org.eclipse.xtext.resource.XtextResource
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor
+import org.eclipse.fx.ide.l10n.nLSDsl.RichVarPart
+import org.eclipse.xtext.nodemodel.util.NodeModelUtils
+import org.eclipse.emf.ecore.EObject
+
+class NLSHighlightingCalculator implements ISemanticHighlightingCalculator {
+
+ override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
+ if( resource == null ) {
+ return
+ }
+
+ resource.allContents.filter(typeof(RichVarPart)).map[e | NodeModelUtils.getNode(e as EObject)].forEach[n|
+ acceptor.addPosition(n.offset-1,n.length+2,NLSHighlightingConfiguration.RICH_TEXT_VAR_ID)
+ ]
+ }
+
+} \ No newline at end of file
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingConfiguration.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingConfiguration.xtend
new file mode 100644
index 000000000..a9551bcf4
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/NLSHighlightingConfiguration.xtend
@@ -0,0 +1,22 @@
+package org.eclipse.fx.ide.l10n.ui.highlighting
+
+import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor
+import org.eclipse.swt.graphics.RGB
+
+class NLSHighlightingConfiguration extends DefaultHighlightingConfiguration {
+ public static final String RICH_TEXT_ID = "nls.richText";
+ public static final String RICH_TEXT_VAR_ID = "nls.richTextVar";
+
+ override configure(IHighlightingConfigurationAcceptor acceptor) {
+ acceptor.acceptDefaultHighlighting(RICH_TEXT_ID, "Template Text", stringTextStyle());
+ acceptor.acceptDefaultHighlighting(RICH_TEXT_VAR_ID, "Template Text", richTextVarStyle());
+ }
+
+ def richTextVarStyle() {
+ val textStyle = defaultTextStyle().copy();
+ textStyle.color = new RGB(127, 0, 85);
+ return textStyle;
+ }
+
+} \ No newline at end of file
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/TokenToAttributeIdMapper.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/TokenToAttributeIdMapper.xtend
new file mode 100644
index 000000000..0186802d1
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/highlighting/TokenToAttributeIdMapper.xtend
@@ -0,0 +1,18 @@
+package org.eclipse.fx.ide.l10n.ui.highlighting
+
+import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultAntlrTokenToAttributeIdMapper
+
+class TokenToAttributeIdMapper extends DefaultAntlrTokenToAttributeIdMapper {
+
+ override protected calculateId(String tokenName, int tokenType) {
+ if(
+ "RULE_RICH_TEXT".equals(tokenName) ||
+ "RULE_RICH_TEXT_START".equals(tokenName) ||
+ "RULE_RICH_TEXT_END".equals(tokenName) ||
+ "RULE_RICH_TEXT_INBETWEEN".equals(tokenName) ) {
+ return NLSHighlightingConfiguration.RICH_TEXT_ID;
+ }
+ return super.calculateId(tokenName, tokenType);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslDescriptionLabelProvider.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslDescriptionLabelProvider.xtend
new file mode 100644
index 000000000..eb5679366
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslDescriptionLabelProvider.xtend
@@ -0,0 +1,24 @@
+/*
+* generated by Xtext
+*/
+package org.eclipse.fx.ide.l10n.ui.labeling
+
+//import org.eclipse.xtext.resource.IEObjectDescription
+
+/**
+ * Provides labels for a IEObjectDescriptions and IResourceDescriptions.
+ *
+ * see http://www.eclipse.org/Xtext/documentation.html#labelProvider
+ */
+class NLSDslDescriptionLabelProvider extends org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider {
+
+ // Labels and icons can be computed like this:
+
+// override text(IEObjectDescription ele) {
+// ele.name.toString
+// }
+//
+// override image(IEObjectDescription ele) {
+// ele.EClass.name + '.gif'
+// }
+}
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslLabelProvider.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslLabelProvider.xtend
new file mode 100644
index 000000000..ea1772bea
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/labeling/NLSDslLabelProvider.xtend
@@ -0,0 +1,29 @@
+/*
+* generated by Xtext
+*/
+package org.eclipse.fx.ide.l10n.ui.labeling
+
+import com.google.inject.Inject
+
+/**
+ * Provides labels for a EObjects.
+ *
+ * see http://www.eclipse.org/Xtext/documentation.html#labelProvider
+ */
+class NLSDslLabelProvider extends org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider {
+
+ @Inject
+ new(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider delegate) {
+ super(delegate);
+ }
+
+ // Labels and icons can be computed like this:
+
+// def text(Greeting ele) {
+// 'A greeting to ' + ele.name
+// }
+//
+// def image(Greeting ele) {
+// 'Greeting.gif'
+// }
+}
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/outline/NLSDslOutlineTreeProvider.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/outline/NLSDslOutlineTreeProvider.xtend
new file mode 100644
index 000000000..831c8cdde
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/outline/NLSDslOutlineTreeProvider.xtend
@@ -0,0 +1,13 @@
+/*
+* generated by Xtext
+*/
+package org.eclipse.fx.ide.l10n.ui.outline
+
+/**
+ * Customization of the default outline structure.
+ *
+ * see http://www.eclipse.org/Xtext/documentation.html#outline
+ */
+class NLSDslOutlineTreeProvider extends org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider {
+
+}
diff --git a/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/quickfix/NLSDslQuickfixProvider.xtend b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/quickfix/NLSDslQuickfixProvider.xtend
new file mode 100644
index 000000000..a6562f210
--- /dev/null
+++ b/bundles/tooling/org.eclipse.fx.ide.l10n.ui/src/org/eclipse/fx/ide/l10n/ui/quickfix/NLSDslQuickfixProvider.xtend
@@ -0,0 +1,26 @@
+/*
+* generated by Xtext
+*/
+package org.eclipse.fx.ide.l10n.ui.quickfix
+
+//import org.eclipse.xtext.ui.editor.quickfix.Fix
+//import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
+//import org.eclipse.xtext.validation.Issue
+
+/**
+ * Custom quickfixes.
+ *
+ * see http://www.eclipse.org/Xtext/documentation.html#quickfixes
+ */
+class NLSDslQuickfixProvider extends org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider {
+
+// @Fix(MyDslValidator::INVALID_NAME)
+// def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {
+// acceptor.accept(issue, 'Capitalize name', 'Capitalize the name.', 'upcase.png') [
+// context |
+// val xtextDocument = context.xtextDocument
+// val firstLetter = xtextDocument.get(issue.offset, 1)
+// xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase)
+// ]
+// }
+}

Back to the top