Bug 502258 - Add PDE template for extensible editor example
Change-Id: I48dff3f9c6cddb1a592904f1daa00182ace749ae
Signed-off-by: Sopot Cela <scela@redhat.com>
diff --git a/ui/org.eclipse.pde.ui.templates/plugin.properties b/ui/org.eclipse.pde.ui.templates/plugin.properties
index c890252..7c3c362 100644
--- a/ui/org.eclipse.pde.ui.templates/plugin.properties
+++ b/ui/org.eclipse.pde.ui.templates/plugin.properties
@@ -56,6 +56,14 @@
<p><b>Extension Used</b></p>\
<li>org.eclipse.ui.editors</li>
+pluginContent.extensibleEditor.name = Plug-in with .target file generic editor extension
+pluginContent.extensibleEditor.description=\
+<p>This wizard creates standard plug-in directory structure and \
+adds the following:</p>\
+<li><b>Extensible Editor</b>. %template.extensibleEditor.desc%</li>\
+<p><b>Extension Used</b></p>\
+<li>org.eclipse.ui.genericeditor.presentationReconcilers</li>
+
pluginContent.view.name = Plug-in with a view
pluginContent.view.description=\
<p>This wizard creates standard plug-in directory structure and \
@@ -190,6 +198,9 @@
newExtension.templates.editor.name = Editor
newExtension.templates.editor.desc = <p>%template.editor.desc%</p>
+newExtension.templates.extensibleEditor.name = Extensible Editor
+newExtension.templates.extensibleEditor.desc = <p>%template.extensibleEditor.desc%</p>
+
newExtension.templates.popupMenus.name = Popup Menu
newExtension.templates.popupMenus.desc = <p>%template.popupMenus.desc%</p>
@@ -238,6 +249,11 @@
template.editor.desc = This template creates a basic XML editor. It has all the basic functions \
of an editor, such as cut, copy, paste, find, etc. It also has syntax highlighting and supports double-clicking.
+template.extensibleEditor.name = Extensible .target Editor
+template.extensibleEditor.desc = This template creates a basic target definition file (.target) editor \
+which provides basic syntax highlighting for this content type.
+
+
template.builder.name = Incremental Builder
template.popupMenus.name = Popup Menu
diff --git a/ui/org.eclipse.pde.ui.templates/plugin.xml b/ui/org.eclipse.pde.ui.templates/plugin.xml
index 4348fca..668ee74 100644
--- a/ui/org.eclipse.pde.ui.templates/plugin.xml
+++ b/ui/org.eclipse.pde.ui.templates/plugin.xml
@@ -116,6 +116,17 @@
</wizard>
<wizard
availableAsShortcut="true"
+ category="templates"
+ icon="$nl$/icons/etool16/newex_wiz.png"
+ id="org.eclipse.pde.ui.newExtension.extensibleEditor"
+ name="%newExtension.templates.extensibleEditor.name"
+ template="org.eclipse.pde.ui.templates.extensibleEditor">
+ <description>
+ %newExtension.templates.extensibleEditor.desc
+ </description>
+ </wizard>
+ <wizard
+ availableAsShortcut="true"
name="%newExtension.templates.help.name"
template="org.eclipse.pde.ui.templates.help"
icon="$nl$/icons/etool16/newex_wiz.png"
@@ -219,6 +230,12 @@
id="org.eclipse.pde.ui.templates.editor">
</template>
<template
+ class="org.eclipse.pde.internal.ui.templates.ide.ExtensbileEditorTemplate"
+ contributingId="org.eclipse.pde.ui.templates.template1"
+ id="org.eclipse.pde.ui.templates.extensibleEditor"
+ name="%template.extensibleEditor.name">
+ </template>
+ <template
contributingId="org.eclipse.ui.popupMenus"
name="%template.popupMenus.name"
class="org.eclipse.pde.internal.ui.templates.ide.PopupMenuTemplate"
@@ -413,6 +430,15 @@
</description>
</wizard>
<wizard
+ class="org.eclipse.pde.internal.ui.templates.ide.ExtensibleEditorNewWizard"
+ icon="$nl$/icons/etool16/newexprj_wiz.png"
+ id="org.eclipse.pde.ui.pluginContent.extensibleEditor"
+ name="%pluginContent.extensibleEditor.name">
+ <description>
+ %pluginContent.extensibleEditor.description
+ </description>
+ </wizard>
+ <wizard
name="%pluginContent.builder.name"
icon="$nl$/icons/etool16/newexprj_wiz.png"
class="org.eclipse.pde.internal.ui.templates.ide.BuilderNewWizard"
diff --git a/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/PDETemplateMessages.java b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/PDETemplateMessages.java
index 8dbf311..5be9377 100644
--- a/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/PDETemplateMessages.java
+++ b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/PDETemplateMessages.java
@@ -22,6 +22,12 @@
public static String HelpTemplate_sampleText;
public static String HelpNewWizard_wiz;
+ public static String ExtensibleEditorNewWizard_wtitle;
+ public static String ExtensibleEditorTemplate_title;
+ public static String ExtensibleEditorTemplate_desc;
+ public static String ExtensibleEditorTemplate_reconcilerClass;
+
+
public static String EditorNewWizard_wtitle;
public static String EditorTemplate_title;
public static String EditorTemplate_desc;
diff --git a/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/ide/ExtensbileEditorTemplate.java b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/ide/ExtensbileEditorTemplate.java
new file mode 100644
index 0000000..0573ef4
--- /dev/null
+++ b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/ide/ExtensbileEditorTemplate.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat Inc. 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:
+ * Sopot Cela (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.pde.internal.ui.templates.ide;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.pde.core.plugin.*;
+import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
+import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
+import org.eclipse.pde.ui.IFieldData;
+import org.eclipse.pde.ui.templates.PluginReference;
+
+public class ExtensbileEditorTemplate extends BaseEditorTemplate {
+
+ public static final String PRESENTATION_RECONCILER_CLASS_NAME = "presentationClass"; //$NON-NLS-1$
+
+ public ExtensbileEditorTemplate() {
+ setPageCount(1);
+ createOptions();
+ }
+
+ @Override
+ public IPluginReference[] getDependencies(String schemaVersion) {
+ IPluginReference[] dep = new IPluginReference[4];
+ dep[0] = new PluginReference("org.eclipse.core.runtime"); //$NON-NLS-1$
+ dep[1] = new PluginReference("org.eclipse.ui"); //$NON-NLS-1$
+ dep[2] = new PluginReference("org.eclipse.jface.text"); //$NON-NLS-1$
+ dep[3] = new PluginReference("org.eclipse.ui.editors"); //$NON-NLS-1$
+ dep[3] = new PluginReference("org.eclipse.ui.genericeditor"); //$NON-NLS-1$
+
+ return dep;
+ }
+
+ @Override
+ public void addPages(Wizard wizard) {
+ WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_EDITOR);
+ page.setTitle(PDETemplateMessages.ExtensibleEditorTemplate_title);
+ page.setDescription(PDETemplateMessages.ExtensibleEditorTemplate_desc);
+ wizard.addPage(page);
+ markPagesAdded();
+ }
+
+ private void createOptions() {
+ addOption(KEY_PACKAGE_NAME, PDETemplateMessages.EditorTemplate_packageName, (String) null, 0);
+ addOption(PRESENTATION_RECONCILER_CLASS_NAME, PDETemplateMessages.ExtensibleEditorTemplate_reconcilerClass,
+ "TargetPlatformPresentationReconciler", //$NON-NLS-1$
+ 0);
+ }
+
+ @Override
+ public String getSectionId() {
+ return "extensibleEditor"; //$NON-NLS-1$
+ }
+
+ @Override
+ public int getNumberOfWorkUnits() {
+ return super.getNumberOfWorkUnits() + 1;
+ }
+
+ @Override
+ protected void initializeFields(IFieldData data) {
+ // In a new project wizard, we don't know this yet - the
+ // model has not been created
+ String id = data.getId();
+ initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
+ }
+
+ @Override
+ public void initializeFields(IPluginModelBase model) {
+ // In the new extension wizard, the model exists so
+ // we can initialize directly from it
+ String pluginId = model.getPluginBase().getId();
+ initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId));
+ }
+
+ @Override
+ public boolean isDependentOnParentWizard() {
+ return true;
+ }
+
+ @Override
+ protected void updateModel(IProgressMonitor monitor) throws CoreException {
+ IPluginBase plugin = model.getPluginBase();
+ IPluginExtension extension = createExtension("org.eclipse.ui.genericeditor.presentationReconcilers", true); //$NON-NLS-1$
+ IPluginModelFactory factory = model.getPluginFactory();
+ IPluginElement extensionElement = factory.createElement(extension);
+ extensionElement.setName("presentationReconciler"); //$NON-NLS-1$
+ extensionElement.setAttribute("class", //$NON-NLS-1$
+ getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PRESENTATION_RECONCILER_CLASS_NAME)); //$NON-NLS-1$
+ extensionElement.setAttribute("contentType", "org.eclipse.pde.targetFile"); //$NON-NLS-1$//$NON-NLS-2$
+ extension.add(extensionElement);
+ plugin.add(extension);
+ }
+
+ @Override
+ protected String getFormattedPackageName(String id) {
+ String packageName = super.getFormattedPackageName(id);
+ if (packageName.length() != 0)
+ return packageName + ".reconciler.presentation"; //$NON-NLS-1$
+ return ".reconciler.presentation"; //$NON-NLS-1$
+ }
+
+}
diff --git a/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/ide/ExtensibleEditorNewWizard.java b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/ide/ExtensibleEditorNewWizard.java
new file mode 100644
index 0000000..79c0ce9
--- /dev/null
+++ b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/ide/ExtensibleEditorNewWizard.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat Inc. 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:
+ * Sopot Cela (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.pde.internal.ui.templates.ide;
+
+import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
+import org.eclipse.pde.ui.IFieldData;
+import org.eclipse.pde.ui.templates.ITemplateSection;
+import org.eclipse.pde.ui.templates.NewPluginTemplateWizard;
+
+public class ExtensibleEditorNewWizard extends NewPluginTemplateWizard {
+
+ @Override
+ public void init(IFieldData data) {
+ super.init(data);
+ setWindowTitle(PDETemplateMessages.ExtensibleEditorNewWizard_wtitle);
+ }
+
+ @Override
+ public ITemplateSection[] createTemplateSections() {
+ return new ITemplateSection[] { new ExtensbileEditorTemplate() };
+ }
+
+}
diff --git a/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/pderesources.properties b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/pderesources.properties
index 45e170f..323e673 100644
--- a/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/pderesources.properties
+++ b/ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/pderesources.properties
@@ -19,6 +19,11 @@
EditorTemplate_fileExtension = F&ile Extension:
EditorTemplate_defaultEditorName = Sample XML Editor
+ExtensibleEditorNewWizard_wtitle = Plug-in with .target file generic editor extension
+ExtensibleEditorTemplate_title = Sample .target syntax highlighting extension
+ExtensibleEditorTemplate_desc = Choose the options that will be used to generate the editor's presentation extension
+ExtensibleEditorTemplate_reconcilerClass = Presentation Reconciler class:
+
HelloOSGiNewWizard_title=Pure OSGi Bundle Wizard
HelloOSGiTemplate_pageTitle=Basic OSGi Bundle
HelloOSGiTemplate_hello=Hello World\!\!
diff --git a/ui/org.eclipse.pde.ui.templates/templates_3.1/extensibleEditor/java/$presentationClass$.java b/ui/org.eclipse.pde.ui.templates/templates_3.1/extensibleEditor/java/$presentationClass$.java
new file mode 100644
index 0000000..e3ec334
--- /dev/null
+++ b/ui/org.eclipse.pde.ui.templates/templates_3.1/extensibleEditor/java/$presentationClass$.java
@@ -0,0 +1,31 @@
+package $packageName$;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.MultiLineRule;
+import org.eclipse.jface.text.rules.Token;
+
+public class $presentationClass$ extends PresentationReconciler {
+
+ public $presentationClass$() {
+ RuleBasedScanner scanner= new RuleBasedScanner();
+ IRule[] rules = new IRule[4];
+ rules[0] = new TargetPlatformRule();
+ rules[1] = new SingleLineRule("\"", "\"",new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(139,69,19)))));
+ rules[2] = new SingleLineRule("<?", "?>",new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(176,176,176)))));
+ rules[3] = new MultiLineRule("<!--", "-->",new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0,100,0)))));
+ scanner.setRules(rules);
+ DefaultDamagerRepairer dr= new DefaultDamagerRepairer(scanner);
+ this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+}
diff --git a/ui/org.eclipse.pde.ui.templates/templates_3.1/extensibleEditor/java/TargetPlatformRule.java b/ui/org.eclipse.pde.ui.templates/templates_3.1/extensibleEditor/java/TargetPlatformRule.java
new file mode 100644
index 0000000..82d5778
--- /dev/null
+++ b/ui/org.eclipse.pde.ui.templates/templates_3.1/extensibleEditor/java/TargetPlatformRule.java
@@ -0,0 +1,56 @@
+package $packageName$;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WordRule;
+
+public class TargetPlatformRule extends WordRule {
+
+String[] tagWords = new String[] {"unit","locations","target","location","targetJRE","launcherArgs"};
+String[] attributeWords = new String[] {"id","version","location", "path", "name","sequenceNumber","includeAllPlatforms","includeConfigurePhase","includeMode","includeSource","type","repository"};
+
+ public TargetPlatformRule(IWordDetector detector) {
+ super(detector);
+ }
+
+ public TargetPlatformRule() {
+ this(new Detector());
+ setupWords();
+ }
+
+ private void setupWords() {
+ for (String word : attributeWords) {
+ this.addWord(word, blue);
+ }
+
+ for (String word : tagWords) {
+ this.addWord(word, red);
+ }
+
+ }
+
+ private IToken blue= new Token(new TextAttribute(Display.getDefault().getSystemColor(SWT.COLOR_BLUE)));
+
+ private IToken red = new Token(new TextAttribute(Display.getDefault().getSystemColor(SWT.COLOR_RED)));
+
+}
+class Detector implements IWordDetector{
+
+ @Override
+ public boolean isWordStart(char c) {
+
+ return Character.isAlphabetic(c);
+ }
+
+ @Override
+ public boolean isWordPart(char c) {
+
+ return Character.isAlphabetic(c);
+ }
+
+}