Author: koen.aers(a)jboss.com
Date: 2008-08-06 07:52:25 -0400 (Wed, 06 Aug 2008)
New Revision: 9564
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml
trunk/flow/plugins/org.jboss.tools.flow.common/schema/
trunk/flow/plugins/org.jboss.tools.flow.common/schema/languages.exsd
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/LanguageRegistry.java
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/build.properties
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editor/GenericModelEditor.java
Log:
add language pluggability
Modified: trunk/flow/plugins/org.jboss.tools.flow.common/build.properties
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/build.properties 2008-08-06 11:44:50
UTC (rev 9563)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/build.properties 2008-08-06 11:52:25
UTC (rev 9564)
@@ -4,5 +4,6 @@
build.properties,\
META-INF/
bin.includes = .,\
- META-INF/
+ META-INF/,\
+ plugin.xml
output.. = bin/
Added: trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml (rev
0)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml 2008-08-06 11:52:25 UTC (rev
9564)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension-point id="languages" name="JBoss Tools Flow Language
Extensions" schema="schema/languages.exsd"/>
+
+</plugin>
Added: trunk/flow/plugins/org.jboss.tools.flow.common/schema/languages.exsd
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/schema/languages.exsd
(rev 0)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/schema/languages.exsd 2008-08-06
11:52:25 UTC (rev 9564)
@@ -0,0 +1,113 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.flow.common"
xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.jboss.tools.flow.common"
id="language" name="JBoss Tools Flow Language Extensions"/>
+ </appinfo>
+ <documentation>
+ This extension points enables to register domain specific languages that can be
edited as graphs or flows. The language is associated with an appropriate editor.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="language"/>
+ </sequence>
+ <attribute name="point" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="language">
+ <complexType>
+ <attribute name="id" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="editor" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editor/GenericModelEditor.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editor/GenericModelEditor.java 2008-08-06
11:44:50 UTC (rev 9563)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editor/GenericModelEditor.java 2008-08-06
11:52:25 UTC (rev 9564)
@@ -61,8 +61,10 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.dialogs.SaveAsDialog;
@@ -71,6 +73,7 @@
import org.jboss.tools.flow.common.Activator;
import org.jboss.tools.flow.common.action.HorizontalAutoLayoutAction;
import org.jboss.tools.flow.common.action.VerticalAutoLayoutAction;
+import org.jboss.tools.flow.common.registry.LanguageRegistry;
/**
* Abstract implementation of a graphical editor.
@@ -85,6 +88,8 @@
private PaletteRoot root;
private OverviewOutlinePage overviewOutlinePage;
+ private String language;
+
public GenericModelEditor() {
setEditDomain(new DefaultEditDomain(this));
}
@@ -97,8 +102,27 @@
return model;
}
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ super.init(site, input);
+ initializeEditDomain();
+ initializeLanguage();
+ }
+
+ protected void initializeEditDomain() {
+ setEditDomain(new DefaultEditDomain(this));
+ }
+
+ protected void initializeLanguage() {
+ language = LanguageRegistry.getLanguageRegisteredFor(getSite().getId());
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
@SuppressWarnings("unchecked")
- protected void createActions() {
+ protected void createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
@@ -162,20 +186,22 @@
IAction showGrid = new ToggleGridAction(getGraphicalViewer());
getActionRegistry().registerAction(showGrid);
-
- IAction layoutVertically = new VerticalAutoLayoutAction(getGraphicalViewer());
+
+ IAction layoutVertically = new VerticalAutoLayoutAction(
+ getGraphicalViewer());
getActionRegistry().registerAction(layoutVertically);
- IAction layoutHorizontally = new HorizontalAutoLayoutAction(getGraphicalViewer());
+ IAction layoutHorizontally = new HorizontalAutoLayoutAction(
+ getGraphicalViewer());
getActionRegistry().registerAction(layoutHorizontally);
-
ContextMenuProvider provider = new GenericContextMenuProvider(
getGraphicalViewer(), getActionRegistry());
getGraphicalViewer().setContextMenu(provider);
- getSite().registerContextMenu("org.jboss.tools.flow.editor.contextmenu",
- provider, getGraphicalViewer());
+ getSite().registerContextMenu(
+ "org.jboss.tools.flow.editor.contextmenu", provider,
+ getGraphicalViewer());
}
-
+
protected abstract EditPartFactory createEditPartFactory();
protected void initializeGraphicalViewer() {
@@ -293,11 +319,11 @@
initializeGraphicalViewer();
}
}
-
+
public IFile getFile() {
- return ((IFileEditorInput) getEditorInput()).getFile();
+ return ((IFileEditorInput) getEditorInput()).getFile();
}
-
+
public IProject getProject() {
IFile file = getFile();
if (file != null) {
@@ -305,10 +331,10 @@
}
return null;
}
-
+
protected abstract void createModel(InputStream is);
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
public Object getAdapter(Class type) {
if (type == IContentOutlinePage.class) {
return getOverviewOutlinePage();
@@ -328,47 +354,47 @@
}
return overviewOutlinePage;
}
-
+
public String getContributorId() {
- return getSite().getId();
+ return getSite().getId();
}
-
+
/**
- * Writes the content of this editor to the given stream.
- * Possible formats are for example SWT.IMAGE_BMP, IMAGE_GIF,
- * IMAGE_JPEG, IMAGE_PNG.
+ * Writes the content of this editor to the given stream. Possible formats
+ * are for example SWT.IMAGE_BMP, IMAGE_GIF, IMAGE_JPEG, IMAGE_PNG.
+ *
* @param stream
* @param format
*/
public void createImage(OutputStream stream, int format) {
- SWTGraphics g = null;
- GC gc = null;
- Image image = null;
- LayerManager layerManager = (LayerManager)
- getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
- IFigure figure = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
- Rectangle r = figure.getBounds();
- try {
- image = new Image(Display.getDefault(), r.width, r.height);
- gc = new GC(image);
- g = new SWTGraphics(gc);
- g.translate(r.x * -1, r.y * -1);
- figure.paint(g);
- ImageLoader imageLoader = new ImageLoader();
- imageLoader.data = new ImageData[] { image.getImageData() };
- imageLoader.save(stream, format);
- } catch (Throwable t) {
- Activator.log(t);
- } finally {
- if (g != null) {
- g.dispose();
- }
- if (gc != null) {
- gc.dispose();
- }
- if (image != null) {
- image.dispose();
- }
- }
+ SWTGraphics g = null;
+ GC gc = null;
+ Image image = null;
+ LayerManager layerManager = (LayerManager) getGraphicalViewer()
+ .getEditPartRegistry().get(LayerManager.ID);
+ IFigure figure = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
+ Rectangle r = figure.getBounds();
+ try {
+ image = new Image(Display.getDefault(), r.width, r.height);
+ gc = new GC(image);
+ g = new SWTGraphics(gc);
+ g.translate(r.x * -1, r.y * -1);
+ figure.paint(g);
+ ImageLoader imageLoader = new ImageLoader();
+ imageLoader.data = new ImageData[] { image.getImageData() };
+ imageLoader.save(stream, format);
+ } catch (Throwable t) {
+ Activator.log(t);
+ } finally {
+ if (g != null) {
+ g.dispose();
+ }
+ if (gc != null) {
+ gc.dispose();
+ }
+ if (image != null) {
+ image.dispose();
+ }
+ }
}
}
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/LanguageRegistry.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/LanguageRegistry.java
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/LanguageRegistry.java 2008-08-06
11:52:25 UTC (rev 9564)
@@ -0,0 +1,40 @@
+package org.jboss.tools.flow.common.registry;
+
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+
+public class LanguageRegistry {
+
+ private static final String languagesExtensionPointId =
"org.jboss.tools.flow.common.languages";
+ private static HashMap<String, String> languageMap = null;
+
+ private static void initializeRegistry() {
+ languageMap = new HashMap<String, String>();
+ IConfigurationElement[] configurationElements =
+ Platform.getExtensionRegistry().getConfigurationElementsFor(languagesExtensionPointId);
+ for (IConfigurationElement configElement: configurationElements) {
+ String id = configElement.getAttribute("id");
+ String editor = configElement.getAttribute("editor");
+ if (id != null && editor != null) {
+ languageMap.put(editor, id);
+ }
+ }
+ }
+
+ public static boolean isLanguageRegisteredFor(String editorId) {
+ if (languageMap == null) {
+ initializeRegistry();
+ }
+ return languageMap.containsKey(editorId);
+ }
+
+ public static String getLanguageRegisteredFor(String editorId) {
+ if (languageMap == null) {
+ initializeRegistry();
+ }
+ return languageMap.get(editorId);
+ }
+
+}