Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.classpath7
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.project28
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/META-INF/MANIFEST.MF27
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/about.html28
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/build.properties10
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/icons/texteditor.bmpbin0 -> 1078 bytes
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.pdoc4
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.xml67
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/Activator.java67
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/editor/PapyrusCommentEditor.java221
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/factory/CommentEditorFactory.java207
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/handler/CommentEditorHandler.java177
-rw-r--r--examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/modelresource/TextEditorModelSharedResource.java102
14 files changed, 952 insertions, 0 deletions
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.classpath b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.project b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.project
new file mode 100644
index 00000000000..fc3da8cd541
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.example.uml.comment.editor.sharedresource</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..44217f8c068
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/META-INF/MANIFEST.MF b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..b1b171f3db3
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/META-INF/MANIFEST.MF
@@ -0,0 +1,27 @@
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
+ org.eclipse.ui.editors;bundle-version="3.8.0",
+ org.eclipse.text,
+ org.eclipse.emf.ecore;bundle-version="2.8.0",
+ org.eclipse.papyrus.example.text.instance;bundle-version="0.10.1",
+ org.eclipse.uml2.uml;bundle-version="4.0.0",
+ org.eclipse.papyrus.infra.core;bundle-version="0.10.1",
+ org.eclipse.emf.transaction,
+ org.eclipse.emf.workspace,
+ org.eclipse.jface.text;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="0.10.1",
+ org.eclipse.gmf.runtime.common.core,
+ org.eclipse.gmf.runtime.emf.type.core
+Bundle-Vendor: Eclipse Modeling Project
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 0.10.1.qualifier
+Bundle-Name: Papyrus Comment Editor Example (Incubation)
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.example.uml.comment.editor.share
+ dresource.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.example.uml.comment.editor.sh
+ aredresource;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/about.html b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/build.properties b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/build.properties
new file mode 100644
index 00000000000..093ba6b8efe
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/build.properties
@@ -0,0 +1,10 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ about.html,\
+ build.properties,\
+ icons/,\
+ plugin.pdoc
+src.includes = about.html
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/icons/texteditor.bmp b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/icons/texteditor.bmp
new file mode 100644
index 00000000000..79df55de06b
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/icons/texteditor.bmp
Binary files differ
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.pdoc b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.pdoc
new file mode 100644
index 00000000000..9bec7dbaf86
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.pdoc
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<doc:Documentation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:doc="http://www.eclipse.org/papyrus/documentation/plugin/documentation" description="This plugin provides a editor for uml.Comment. The informations are stored in the .notation">
+ <referent firstName="vincent" lastName="lorenzo" eMail="vincent.lorenzo@cea.fr" currentCompany="CEA-LIST"/>
+</doc:Documentation>
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.xml b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.xml
new file mode 100644
index 00000000000..cb5d3c3b68e
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/plugin.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.infra.core.model">
+ <model
+ classname="org.eclipse.papyrus.example.uml.comment.editor.sharedresource.modelresource.TextEditorModelSharedResource">
+ </model>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ description="Open a Comment Editor (Shared Resource)"
+ id="org.eclipse.papyrus.example.uml.comment.editor.command.sharedresource"
+ name="Open a Comment Editor (Shared Resource)">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.example.uml.comment.editor.sharedresource.handler.CommentEditorHandler"
+ commandId="org.eclipse.papyrus.example.uml.comment.editor.command.sharedresource">
+ <activeWhen>
+ <and>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.core.papyrusDiagram">
+ <editorDiagram
+ factoryClass="org.eclipse.papyrus.example.uml.comment.editor.sharedresource.factory.CommentEditorFactory"
+ icon="icons/texteditor.bmp">
+ </editorDiagram>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup">
+ <command
+ commandId="org.eclipse.papyrus.example.uml.comment.editor.command.sharedresource"
+ icon="icons/texteditor.bmp"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <and>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </and>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+
+</plugin>
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/Activator.java b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/Activator.java
new file mode 100644
index 00000000000..0195681d372
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/Activator.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.uml.comment.editor.sharedresource;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.example.uml.comment.editor.sharedresource"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (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);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/editor/PapyrusCommentEditor.java b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/editor/PapyrusCommentEditor.java
new file mode 100644
index 00000000000..02bc18d994d
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/editor/PapyrusCommentEditor.java
@@ -0,0 +1,221 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.uml.comment.editor.sharedresource.editor;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.ITextListener;
+import org.eclipse.jface.text.TextEvent;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.example.text.instance.papyrustextinstance.PapyrusTextInstance;
+import org.eclipse.papyrus.example.uml.comment.editor.sharedresource.Activator;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IStorageEditorInput;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.uml2.uml.Comment;
+
+public class PapyrusCommentEditor extends TextEditor {
+
+ /** the service registry */
+ protected final ServicesRegistry registry;
+
+ /** the papyrus text instance */
+ protected final PapyrusTextInstance papyrusTextInstance;
+
+ /** the text listener */
+ protected ITextListener listener;
+
+ /** the editing domain */
+ protected TransactionalEditingDomain domain;
+
+ public static final String EDITOR_DEFAULT_NAME = "Comment Editor Shared Resource";
+
+ public static final String EDITOR_TYPE = "CommentEditorSharedResource";
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param registry
+ * @param papyrusTextInstance
+ */
+ public PapyrusCommentEditor(final ServicesRegistry registry, final PapyrusTextInstance papyrusTextInstance) {
+ super();
+ this.registry = registry;
+ this.papyrusTextInstance = papyrusTextInstance;
+ try {
+ domain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite,
+ * org.eclipse.jface.text.source.IVerticalRuler, int)
+ *
+ * @param parent
+ * @param ruler
+ * @param styles
+ * @return
+ */
+ @Override
+ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
+ ISourceViewer viewer = super.createSourceViewer(parent, ruler, styles);
+ //we add a listener on the viewer to be notified when the text is edited
+ //TODO try to improve, because we execute a command for each character
+ listener = new ITextListener() {
+
+ //we edit the uml.Comment
+ public void textChanged(TextEvent event) {
+ String currentText = getSourceViewer().getTextWidget().getText();
+ Comment cmt = (Comment)papyrusTextInstance.getEditedObject();
+ EStructuralFeature feature = cmt.eClass().getEStructuralFeature("body");
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(cmt);
+ SetRequest request = new SetRequest(domain, cmt, feature, currentText);
+ ICommand command = elementEditService.getEditCommand(request);
+ if(command.canExecute()) {
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ }
+ }
+ };
+
+ viewer.addTextListener(listener);
+
+ return viewer;
+ }
+
+ /**
+ * We override this method because setInput can't be overriden for TextEditor.
+ * We replace the default papyrus input by our input for Comment
+ *
+ * @see org.eclipse.ui.editors.text.TextEditor#doSetInput(org.eclipse.ui.IEditorInput)
+ *
+ * @param input
+ * @throws CoreException
+ */
+ @Override
+ protected void doSetInput(IEditorInput input) throws CoreException {
+ String string = ((Comment)papyrusTextInstance.getEditedObject()).getBody();
+ if(string == null) {
+ string = "";
+ }
+ IStorage storage = new TextStorage(string);
+ super.doSetInput(new TextInput(storage));
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.editors.text.TextEditor#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ //we remove the listener
+ getSourceViewer().removeTextListener(listener);
+ super.dispose();
+ }
+
+
+ //for this classes , see : http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_something_that_is_not_a_file%3F
+ class TextStorage implements IStorage {
+
+ private String string;
+
+ TextStorage(String input) {
+ this.string = input;
+ }
+
+ public InputStream getContents() throws CoreException {
+ return new ByteArrayInputStream(string.getBytes());
+ }
+
+ public IPath getFullPath() {
+ return null;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ public String getName() {
+ int len = Math.min(5, string.length());
+ return string.substring(0, len).concat("..."); //$NON-NLS-1$
+ }
+
+ public boolean isReadOnly() {
+ return false;
+ }
+ }
+
+ //for this classes , see : http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_something_that_is_not_a_file%3F
+ class TextInput implements IStorageEditorInput {
+
+ private IStorage storage;
+
+ TextInput(IStorage storage) {
+ this.storage = storage;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return storage.getName();
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public IStorage getStorage() {
+ return storage;
+ }
+
+ public String getToolTipText() {
+ return "String-based file: " + storage.getName();
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+ }
+
+}
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/factory/CommentEditorFactory.java b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/factory/CommentEditorFactory.java
new file mode 100644
index 00000000000..94c266fd4d3
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/factory/CommentEditorFactory.java
@@ -0,0 +1,207 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.uml.comment.editor.sharedresource.factory;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.example.text.instance.papyrustextinstance.PapyrusTextInstance;
+import org.eclipse.papyrus.example.uml.comment.editor.sharedresource.Activator;
+import org.eclipse.papyrus.example.uml.comment.editor.sharedresource.editor.PapyrusCommentEditor;
+import org.eclipse.papyrus.infra.core.editor.BackboneException;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.AbstractEditorFactory;
+import org.eclipse.papyrus.infra.core.multidiagram.actionbarcontributor.ActionBarContributorRegistry;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorActionBarContributor;
+
+
+public class CommentEditorFactory extends AbstractEditorFactory {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param editorClass
+ * the editor class
+ * @param editorType
+ * the type of editor
+ */
+ public CommentEditorFactory() {
+ super(PapyrusCommentEditor.class, PapyrusCommentEditor.EDITOR_TYPE);
+ }
+
+ /**
+ * Create the IPageModel that is used by the SashWindows to manage the editor.
+ *
+ * @see org.eclipse.papyrus.infra.core.editorsfactory.IEditorFactory#createIPageModel(java.lang.Object)
+ *
+ * @param pageIdentifier
+ * The model pushed in the sashmodel by the creation command
+ * @return A model implementing the IPageModel
+ */
+ public IPageModel createIPageModel(Object pageIdentifier) {
+ return new TextEditorModel(pageIdentifier, getServiceRegistry());
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.editorsfactory.IEditorFactory#isPageModelFactoryFor(java.lang.Object)
+ *
+ * @param pageIdentifier
+ * @return
+ */
+ public boolean isPageModelFactoryFor(Object pageIdentifier) {
+ if(pageIdentifier instanceof PapyrusTextInstance) {
+ return ((PapyrusTextInstance)pageIdentifier).getType().equals(this.getExpectedType());
+ }
+ return false;
+ }
+
+ /**
+ * IEditorModel used internally by the SashContainer. This model know how to handle IEditor creation.
+ *
+ *
+ *
+ */
+ class TextEditorModel implements IEditorModel {
+
+
+ /**
+ * The servicesRegistry provided at creation.
+ */
+ private ServicesRegistry servicesRegistry;
+
+ /**
+ * The created editor.
+ */
+ private IEditorPart editor;
+
+ /**
+ * The raw model stored in the SashProvider.
+ */
+ private PapyrusTextInstance rawModel;
+
+ /**
+ *
+ * Constructor.
+ */
+ public TextEditorModel(Object pageIdentifier, ServicesRegistry servicesRegistry) {
+ rawModel = (PapyrusTextInstance)pageIdentifier;
+ this.servicesRegistry = servicesRegistry;
+ }
+
+ /**
+ * Create the IEditor for the diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel#createIEditorPart()
+ * @return
+ * @throws PartInitException
+ *
+ */
+ public IEditorPart createIEditorPart() throws PartInitException {
+ try {
+ //we use this way when there is one factory for several editor types
+ // Constructor<?> c = getDiagramClass().getConstructor(ServicesRegistry.class, PapyrusTextInstance.class);
+ // editor = (IEditorPart)c.newInstance(servicesRegistry, rawModel);
+
+ //we use this way when there is only one editor type
+ editor = new PapyrusCommentEditor(servicesRegistry, rawModel);
+ return editor;
+
+ } catch (Exception e) {
+ // Lets propagate. This is an implementation problem that should be solved by
+ // programmer.
+ throw new PartInitException("Can't create TextEditor", e); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
+ * Get the action bar requested by the Editor.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel#getActionBarContributor()
+ * @return
+ *
+ */
+ public EditorActionBarContributor getActionBarContributor() {
+
+ String actionBarId = editorDescriptor.getActionBarContributorId();
+
+ // Do nothing if no EditorActionBarContributor is specify.
+ if(actionBarId == null || actionBarId.length() == 0) {
+ return null;
+ }
+
+ // Try to get it.
+
+ // Get ServiceRegistry
+ // ServicesRegistry serviceRegistry = getServicesRegistry();
+ ActionBarContributorRegistry registry;
+ try {
+ registry = servicesRegistry.getService(ActionBarContributorRegistry.class);
+ } catch (ServiceException e) {
+ // Service not found
+ Activator.log.error(e);
+ return null;
+ }
+
+ try {
+ return registry.getActionBarContributor(actionBarId);
+ } catch (BackboneException e) {
+ Activator.log.error(e);
+ return null;
+ }
+ }
+
+ /**
+ * Get the underlying RawModel. Return the Diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getRawModel()
+ * @return
+ *
+ */
+ public Object getRawModel() {
+ return rawModel;
+ }
+
+ /**
+ * Get the icon to be shown by Tabs
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabIcon()
+ * @return
+ *
+ */
+ public Image getTabIcon() {
+ ImageDescriptor imageDescriptor = getEditorDescriptor().getIcon();
+ if(imageDescriptor == null) {
+ return null;
+ }
+ return imageDescriptor.createImage();
+ }
+
+ /**
+ * Get the title of the Diagram.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabTitle()
+ * @return
+ *
+ */
+ public String getTabTitle() {
+ return rawModel.getName();
+ }
+ }
+}
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/handler/CommentEditorHandler.java b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/handler/CommentEditorHandler.java
new file mode 100644
index 00000000000..c557a58933c
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/handler/CommentEditorHandler.java
@@ -0,0 +1,177 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.uml.comment.editor.sharedresource.handler;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.AbstractEMFOperation;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.commands.CheckedOperationHistory;
+import org.eclipse.papyrus.example.text.instance.papyrustextinstance.PapyrusTextInstance;
+import org.eclipse.papyrus.example.text.instance.papyrustextinstance.PapyrustextinstanceFactory;
+import org.eclipse.papyrus.example.uml.comment.editor.sharedresource.Activator;
+import org.eclipse.papyrus.example.uml.comment.editor.sharedresource.editor.PapyrusCommentEditor;
+import org.eclipse.papyrus.example.uml.comment.editor.sharedresource.modelresource.TextEditorModelSharedResource;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Comment;
+
+
+public class CommentEditorHandler extends AbstractHandler {
+
+
+ public CommentEditorHandler(){
+ }
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ return getSelection().size() == 1;
+ }
+
+ /**
+ *
+ * @return
+ * the current selection
+ */
+ protected List<EObject> getSelection() {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ List<EObject> currentSelection = new ArrayList<EObject>();
+ Iterator<?> iter = ((IStructuredSelection)selection).iterator();
+ while(iter.hasNext()) {
+ Object current = iter.next();
+ if(current instanceof IAdaptable){
+ EObject tmp = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(tmp!=null){
+ if(tmp instanceof Comment){
+ currentSelection.add(tmp);
+ }
+ }
+ }
+ }
+ return currentSelection;
+ }
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ try {
+
+ runAsTransaction();
+ } catch (ServiceException e) {
+ throw new ExecutionException("I can't create CompareEditor", e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * Run the command as a transaction.
+ * Create a Transaction and delegate the command to {@link #doExecute(ServicesRegistry)}.
+ *
+ * @throws ServiceException
+ *
+ */
+ public void runAsTransaction() throws ServiceException {
+ final ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
+ TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
+
+ //Create the transactional command
+ AbstractEMFOperation command = new AbstractEMFOperation(domain, "Create CompareEditor") { //$NON-NLS-1$
+
+ @Override
+ protected IStatus doExecute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ try {
+ CommentEditorHandler.this.doExecute(serviceRegistry);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ return Status.CANCEL_STATUS;
+ } catch (NotFoundException e) {
+ Activator.log.error(e);
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+ };
+
+ // Execute the command
+ try {
+ CheckedOperationHistory.getInstance().execute(command, new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ Activator.log.error("I can't create CompareEditor", e); //$NON-NLS-1$
+ }
+
+ }
+
+
+ /**
+ * Do the execution of the command.
+ *
+ * @param serviceRegistry
+ * @throws ServiceException
+ * @throws NotFoundException
+ */
+ public void doExecute(final ServicesRegistry serviceRegistry) throws ServiceException, NotFoundException {
+ Object editorModel = createEditorModel(serviceRegistry);
+ // Get the mngr allowing to add/open new editor.
+ IPageMngr pageMngr = ServiceUtils.getInstance().getIPageMngr(serviceRegistry);
+ // add the new editor model to the sash.
+ pageMngr.openPage(editorModel);
+
+ }
+
+ /**
+ * Create a model identifying the editor. This model will be saved with the sash
+ *
+ * @return
+ * @throws ServiceException
+ * @throws NotFoundException
+ * The model where to save the TableInstance is not found.
+ */
+ protected Object createEditorModel(final ServicesRegistry serviceRegistry) throws ServiceException, NotFoundException {
+ PapyrusTextInstance editorModel = PapyrustextinstanceFactory.eINSTANCE.createPapyrusTextInstance();
+ editorModel.setEditedObject(getSelection().get(0));
+ editorModel.setType(PapyrusCommentEditor.EDITOR_TYPE);
+ editorModel.setName(PapyrusCommentEditor.EDITOR_DEFAULT_NAME);
+ TextEditorModelSharedResource model = (TextEditorModelSharedResource)ServiceUtils.getInstance().getModelSet(serviceRegistry).getModelChecked(TextEditorModelSharedResource.MODEL_ID);
+ model.addPapyrusTextInstance(editorModel);
+ return editorModel;
+ }
+}
diff --git a/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/modelresource/TextEditorModelSharedResource.java b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/modelresource/TextEditorModelSharedResource.java
new file mode 100644
index 00000000000..608e4b0e868
--- /dev/null
+++ b/examples/org.eclipse.papyrus.example.uml.comment.editor.sharedresource/src/org/eclipse/papyrus/example/uml/comment/editor/sharedresource/modelresource/TextEditorModelSharedResource.java
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.uml.comment.editor.sharedresource.modelresource;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.example.text.instance.papyrustextinstance.PapyrusTextInstance;
+import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource;
+import org.eclipse.papyrus.infra.core.resource.IModel;
+
+
+public class TextEditorModelSharedResource extends AbstractModelWithSharedResource<PapyrusTextInstance> implements IModel {
+
+
+ /**
+ * File extension used for notation.
+ */
+ public static final String NOTATION_FILE_EXTENSION = "notation"; //$NON-NLS-1$
+
+ /**
+ * Model ID.
+ */
+ public static final String MODEL_ID = "org.eclipse.papyrus.example.text.TextEditorModelSharedResource"; //$NON-NLS-1$
+
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public TextEditorModelSharedResource() {
+
+ }
+
+
+ /**
+ * Get the file extension used for this model.
+ *
+ * @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getModelFileExtension()
+ *
+ * @return
+ */
+ @Override
+ protected String getModelFileExtension() {
+ return NOTATION_FILE_EXTENSION;
+ }
+
+ /**
+ * Get the identifier used to register this model.
+ *
+ * @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getIdentifier()
+ *
+ * @return
+ */
+ @Override
+ public String getIdentifier() {
+ return MODEL_ID;
+ }
+
+
+ /**
+ * Add a new initialized {@link PapyrusEMFCompareInstance} to the model.
+ *
+ * @param compareInstance
+ * The compareInstance to add.
+ */
+ public void addPapyrusTextInstance(PapyrusTextInstance compareInstance) {
+ getResource().getContents().add(compareInstance);
+ }
+
+ /**
+ * Add a new initialized {@link PapyrusEMFCompareInstance} to the model.
+ *
+ * @param compareInstance
+ * The compareInstance to add.
+ */
+ public void removePapyrusTextInstance(PapyrusTextInstance compareInstance) {
+ getResource().getContents().remove(compareInstance);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#isModelRoot(org.eclipse.emf.ecore.EObject)
+ *
+ * @param object
+ * @return
+ */
+ @Override
+ protected boolean isModelRoot(EObject object) {
+ return false;
+ }
+
+}

Back to the top