Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui')
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/AlfUiModule.java25
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java22
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditedResourceProvider.java61
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorKeyListener.java89
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorUtils.java181
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfPopupEditor.java95
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfSerializer.java168
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/OpenAlfEditorHandler.java151
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfDescriptionLabelProvider.java37
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfLabelProvider.java44
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/outline/AlfOutlineTreeProvider.java24
-rw-r--r--sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/quickfix/AlfQuickfixProvider.java32
12 files changed, 929 insertions, 0 deletions
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/AlfUiModule.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/AlfUiModule.java
new file mode 100644
index 00000000000..739ac78d8a7
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/AlfUiModule.java
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * Use this class to register components to be used within the IDE.
+ */
+public class AlfUiModule extends org.eclipse.papyrus.alf.ui.AbstractAlfUiModule {
+ public AlfUiModule(AbstractUIPlugin plugin) {
+ super(plugin);
+ }
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java
new file mode 100644
index 00000000000..55ae0a68f57
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/contentassist/AlfProposalProvider.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.contentassist;
+
+import org.eclipse.papyrus.alf.ui.contentassist.AbstractAlfProposalProvider;
+/**
+ * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
+ */
+public class AlfProposalProvider extends AbstractAlfProposalProvider {
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditedResourceProvider.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditedResourceProvider.java
new file mode 100644
index 00000000000..8a0e64d4573
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditedResourceProvider.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.integration;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.IGrammarAccess;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
+
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+
+/**
+ * @author ac221913 - Initial contribution and API
+ */
+@SuppressWarnings("restriction")
+public class AlfEditedResourceProvider implements IEditedResourceProvider {
+
+ public static final String SYNTHETIC_SCHEME = "synthetic";
+
+ protected Provider<XtextResourceSet> resourceSetProvider;
+
+ protected IGrammarAccess grammarAccess;
+
+ protected Injector xtextInjector ;
+
+ /**
+ * @param xtextInjector
+ *
+ */
+ public AlfEditedResourceProvider(Injector xtextInjector) {
+ this.xtextInjector = xtextInjector ;
+ }
+
+ public XtextResource createResource() {
+ resourceSetProvider = xtextInjector.getProvider(XtextResourceSet.class) ;
+ ResourceSet resourceSet = resourceSetProvider.get();
+ grammarAccess = xtextInjector.getInstance(IGrammarAccess.class) ;
+ Resource grammarResource = resourceSet.createResource(URI.createURI(SYNTHETIC_SCHEME + ":/" + grammarAccess.getGrammar().getName() + ".xtext"));
+ grammarResource.getContents().add(EcoreUtil.copy(grammarAccess.getGrammar()));
+ XtextResource result = (XtextResource) resourceSet.createResource(URI.createURI(SYNTHETIC_SCHEME + ":/" + grammarAccess.getGrammar().getName() + ".alf"));
+ resourceSet.getResources().add(result);
+ return result ;
+ }
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorKeyListener.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorKeyListener.java
new file mode 100644
index 00000000000..a20fcab6906
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorKeyListener.java
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.integration;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.VerifyKeyListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess;
+
+@SuppressWarnings("restriction")
+public class AlfEditorKeyListener extends KeyAdapter implements VerifyKeyListener {
+
+ protected Element contextElement ;
+
+ protected EmbeddedEditorModelAccess embeddedEditorAccess ;
+
+ protected TransactionalEditingDomain editingDomain ;
+
+ protected Object[] args ;
+
+ public AlfEditorKeyListener(Element contextElement, Object[] args, EmbeddedEditorModelAccess editorModelAccess) {
+ super();
+ this.contextElement = contextElement ;
+ this.embeddedEditorAccess = editorModelAccess;
+ this.args = args ;
+ editingDomain = (TransactionalEditingDomain)EMFHelper.resolveEditingDomain(contextElement) ;
+ }
+
+ @Override
+ public void keyPressed(KeyEvent event) {
+ int keyCode = event.keyCode;
+ if ((event.stateMask & SWT.CTRL) != 0 && ((keyCode == SWT.KEYPAD_CR) || (keyCode == SWT.CR))) {
+ boolean success = new AlfSerializer().serialize(this.contextElement, embeddedEditorAccess.getSerializedModel(), this.args) ;
+ int messageDialogKind = success ? MessageDialog.INFORMATION : MessageDialog.ERROR ;
+ String message = "" ;
+ if (success) {
+ message += "- Alf statements successfully compiled.\n" ;
+ message += "- Textual representation comment successfully generated or updated" ;
+ MessageDialog.open(messageDialogKind, Display.getCurrent().getActiveShell(), "Serialization info", message, SWT.NONE) ;
+ }
+ else {
+ message += "- Compilation failed.\n" ;
+ message += "- Textual representation comment successfully generated or updated" ;
+ MessageDialog.open(messageDialogKind, Display.getCurrent().getActiveShell(), "Serialization info", message, SWT.NONE) ;
+ }
+ }
+ if ((event.stateMask & SWT.ALT) != 0 && ((keyCode == SWT.KEYPAD_CR) || (keyCode == SWT.CR))) {
+ boolean success = new AlfSerializer().validate(this.contextElement, embeddedEditorAccess.getSerializedModel(), this.args) ;
+ int messageDialogKind = success ? MessageDialog.INFORMATION : MessageDialog.ERROR ;
+ String message = "" ;
+ if (success) {
+ message += "Specification is valid." ;
+ MessageDialog.open(messageDialogKind, Display.getCurrent().getActiveShell(), "Validation info", message, SWT.NONE) ;
+ }
+ else {
+ message += "Validation failed" ;
+ MessageDialog.open(messageDialogKind, Display.getCurrent().getActiveShell(), "Validation info", message, SWT.NONE) ;
+ }
+ }
+ }
+
+ public void verifyKey(VerifyEvent event) {
+ if ((event.stateMask & SWT.CTRL) != 0 && ((event.keyCode == SWT.KEYPAD_CR) || (event.keyCode == SWT.CR))) {
+ event.doit = false;
+ }
+ if ((event.stateMask & SWT.ALT) != 0 && ((event.keyCode == SWT.KEYPAD_CR) || (event.keyCode == SWT.CR))) {
+ event.doit = false;
+ }
+ }
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorUtils.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorUtils.java
new file mode 100644
index 00000000000..83789fde993
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfEditorUtils.java
@@ -0,0 +1,181 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.integration;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.alf.compiler.IAlfCompiler;
+import org.eclipse.papyrus.uml.extensionpoints.profile.RegisteredProfile;
+import org.eclipse.papyrus.uml.extensionpoints.utils.Util;
+import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
+import org.eclipse.uml2.uml.Activity;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * @author ac221913
+ *
+ */
+public class AlfEditorUtils {
+
+ public static String ACTION_LANGUAGE_PROFILE_NAME = "ActionLanguage" ;
+
+ public static String ALF_COMPILER_EXTENSION_POINT_ID = "org.eclipse.papyrus.alf.alfcompiler" ;
+
+ protected static IAlfCompiler alfCompiler ;
+
+ /**
+ * The Action Language profile
+ */
+ protected static Profile actionLanguageProfile ;
+
+ /**
+ * The TextualRepresentation stereotype (from the Action Language profile)
+ */
+ protected static Stereotype textualRepresentationStereotype ;
+
+ public static void clean() {
+ actionLanguageProfile = null ;
+ textualRepresentationStereotype = null ;
+ }
+
+ /**
+ * @param element
+ * @param args
+ * @return
+ */
+ public static String getTextualRepresentation(Element element, Object[] args) {
+ String textualRepresentation = "" ;
+ Comment textualRepresentationComment = getTextualRepresentationComment(element) ;
+ if (textualRepresentationComment == null) {
+ textualRepresentation += generateTextualRepresentation(element) ;
+ }
+ else {
+ textualRepresentation += textualRepresentationComment.getBody() ;
+ }
+ return textualRepresentation ;
+ }
+
+ /**
+ * @param element
+ * @return
+ */
+ public static Comment getTextualRepresentationComment(Element element) {
+ Comment textualRepresentationComment = null ;
+ for (Comment comment : element.getOwnedComments()) {
+ if (comment.getBody() != null && isATextualRepresentationComment(comment)) {
+ textualRepresentationComment = comment ;
+ }
+ }
+ return textualRepresentationComment ;
+ }
+
+ /**
+ * @param element
+ * @return
+ */
+ public static String generateTextualRepresentation(Element element) {
+ // Provides only very basic support for activities. TODO to be completed
+ Activity activity = (Activity)element ;
+ String metaclassName = activity.eClass().getName() ;
+ String textualRepresentation = "/* Generated textual representation of " + metaclassName + " " + activity.getQualifiedName() + " */\n\n";
+ textualRepresentation += "namespace " + activity.getNamespace().getQualifiedName() + " ;\n\n" ;
+ textualRepresentation += "activity " + activity.getName() + "() { \n\n}" ;
+ return textualRepresentation ;
+ }
+
+ /**
+ * @param comment
+ * @return
+ */
+ public static boolean isATextualRepresentationComment(Comment comment) {
+ if (textualRepresentationStereotype != null) {
+ return comment.getAppliedStereotypes().contains(textualRepresentationStereotype) ;
+ }
+ else {
+ // There is a chance to find it if the root model has ActionLanguage profile applied
+ // In this case, the stereotype is included in comment.getApplicableStereotypes()
+ List<Stereotype> applicableStereotypes = comment.getApplicableStereotypes() ;
+ for (int i = 0 ; i < applicableStereotypes.size() && textualRepresentationStereotype == null ; i++) {
+ if (applicableStereotypes.get(i).getName().equals("TextualRepresentation")) {
+ textualRepresentationStereotype = applicableStereotypes.get(i) ;
+ }
+ }
+ }
+ return textualRepresentationStereotype != null ;
+ }
+
+ /**
+ * @param element
+ * @return
+ */
+ public static boolean isActionLanguageProfileApplied(Element element) {
+ if (actionLanguageProfile == null) {
+ RegisteredProfile registeredActionLanguageProfile = RegisteredProfile.getRegisteredProfile(ACTION_LANGUAGE_PROFILE_NAME) ;
+ URI modelUri = registeredActionLanguageProfile.uri;
+ Model root = element.getModel() ;
+ Resource modelResource = Util.getResourceSet(root).getResource(modelUri, true);
+ if(modelResource.getContents().get(0) instanceof Profile) {
+ actionLanguageProfile = (Profile)modelResource.getContents().get(0) ;
+ }
+ }
+ List<Profile> appliedProfiles = element.getModel().getAppliedProfiles() ;
+ return appliedProfiles.contains(actionLanguageProfile) ;
+ }
+
+ /**
+ * @param element
+ * @return
+ */
+ public static Comment createTextualRepresentationComment(Element element) {
+ Comment textualRepresentationComment = element.createOwnedComment() ;
+ if (! isActionLanguageProfileApplied(element)) {
+ PackageUtil.applyProfile((org.eclipse.uml2.uml.Package)element.getModel(), actionLanguageProfile, true) ;
+ }
+ clean() ;
+ isATextualRepresentationComment(textualRepresentationComment) ; // This is just to force retrieval of the textual representation stereotype
+ textualRepresentationComment.applyStereotype(textualRepresentationStereotype) ;
+ return textualRepresentationComment ;
+ }
+
+ public static IAlfCompiler getAlfCompiler() {
+ if (alfCompiler == null) {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] config = registry.getConfigurationElementsFor(ALF_COMPILER_EXTENSION_POINT_ID);
+ try {
+ for(int i = 0; i < config.length; i++) {
+ IConfigurationElement e = config[i];
+ final Object o = e.createExecutableExtension("class");
+ if (o != null) {
+ alfCompiler = (IAlfCompiler)o ;
+ }
+ }
+ } catch (CoreException ex) {
+ System.out.println(ex.getMessage());
+ } catch (Exception ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
+ return alfCompiler ;
+ }
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfPopupEditor.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfPopupEditor.java
new file mode 100644
index 00000000000..a08ecea1d66
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfPopupEditor.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.integration;
+
+import org.eclipse.papyrus.alf.ui.internal.AlfActivator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess;
+import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
+
+import com.google.inject.Injector;
+
+@SuppressWarnings("restriction")
+public class AlfPopupEditor {
+
+ /**
+ * The context element being edited
+ */
+ protected Element contextElement ;
+
+ /**
+ * Optional arguments for the creation of the AlfPopupEditor
+ *
+ */
+ protected Object[] args ;
+
+ /**
+ * The Injector for the Alf editor
+ */
+ protected Injector alfInjector = null;
+
+ /**
+ * The parent Shell for embedding the Alf editor
+ */
+ protected Shell alfEditorParentComposite ;
+
+ /**
+ * The model access to the Alf editor embedded in alfEditorParentComposite
+ */
+ protected EmbeddedEditorModelAccess embeddedEditorAccess ;
+
+ public AlfPopupEditor (Element contextElement, Object[] args) {
+ if (contextElement == null)
+ return ;
+ this.contextElement = contextElement ;
+ this.alfInjector = AlfActivator.getInstance().getInjector("org.eclipse.papyrus.alf.Alf");
+ this.args = args ;
+ }
+
+ public void openEditor() {
+ AlfEditorUtils.clean() ;
+ // Creation of the parent shell
+ this.alfEditorParentComposite = new Shell(SWT.RESIZE | SWT.DIALOG_TRIM | SWT.ON_TOP) ;
+ String title = "" ;
+ if (contextElement != null) {
+ if (contextElement instanceof NamedElement) {
+ title += "Editing " + contextElement.eClass().getName() + " " + ((NamedElement)contextElement).getQualifiedName() ;
+ }
+ }
+ this.alfEditorParentComposite.setLayout(new FillLayout()) ;
+ this.alfEditorParentComposite.setText(title) ;
+ // Creation of the embedded xtext editor
+ IEditedResourceProvider embeddedAlfResourceProvider = new AlfEditedResourceProvider(this.alfInjector);
+ EmbeddedEditorFactory editorFactory = this.alfInjector.getInstance(EmbeddedEditorFactory.class) ;
+ EmbeddedEditor editor = editorFactory.newEditor(embeddedAlfResourceProvider).showErrorAndWarningAnnotations().withParent(this.alfEditorParentComposite);
+ this.embeddedEditorAccess = editor.createPartialEditor();
+ this.embeddedEditorAccess.updateModel("", AlfEditorUtils.getTextualRepresentation(this.contextElement, this.args), "") ;
+ this.registerKeyListener(editor.getViewer().getTextWidget()) ;
+ this.alfEditorParentComposite.setVisible(true);
+ }
+
+ protected void registerKeyListener(StyledText textWidget) {
+ AlfEditorKeyListener keyListener = new AlfEditorKeyListener(this.contextElement, this.args, this.embeddedEditorAccess) ;
+ textWidget.addVerifyKeyListener(keyListener);
+ textWidget.addKeyListener(keyListener);
+ }
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfSerializer.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfSerializer.java
new file mode 100644
index 00000000000..62195ad9aa7
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/AlfSerializer.java
@@ -0,0 +1,168 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.alf.ui.integration;
+
+import java.util.List;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.alf.compiler.IAlfCompiler;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * A default, abstract reconciliation strategy for Alf.
+ * Introduces a new method reconcileWithError, which only adds a textual representation comment to the edited element
+ *
+ * @author CEA LIST - Initial contribution and API
+ *
+ */
+public class AlfSerializer {
+
+ /**
+ * Adds a textual representation comment to the edit modelObject, if this eObject is a uml Element
+ *
+ * @param graphicalEditPart
+ * @param modelObject
+ * @param newTextualRepresentation
+ */
+ public boolean serialize(Element contextElement, String newTextualRepresentation, Object[] args) {
+ TransactionalEditingDomain domain = (TransactionalEditingDomain)EMFHelper.resolveEditingDomain(contextElement) ;
+ CompileCommand updateCommand = new CompileCommand(contextElement, newTextualRepresentation, args, domain);
+ domain.getCommandStack().execute(updateCommand) ;
+ return updateCommand.getCompileResult() ;
+ }
+
+ /**
+ * @author CEA LIST
+ *
+ * A command for updating the context UML model
+ */
+ protected class CompileCommand extends RecordingCommand {
+
+ protected Element element ;
+ protected String textualRepresentation ;
+ protected Object[] args ;
+ protected boolean compileResult = false ;
+
+ public CompileCommand(Element element, String textualRepresentation, Object[] args, TransactionalEditingDomain domain) {
+ super(domain) ;
+ this.element = element ;
+ this.textualRepresentation = textualRepresentation ;
+ this.args = args ;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor
+ * , org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected void doExecute() {
+ // first tries to compile the textual representation
+ IAlfCompiler alfCompiler = AlfEditorUtils.getAlfCompiler() ;
+ if (alfCompiler != null) {
+ this.compileResult = alfCompiler.compile(element, textualRepresentation, args) ;
+ }
+ else {
+ MessageDialog.open(MessageDialog.ERROR, Display.getCurrent().getActiveShell(), "Validation info", "No registered Alf Compiler", SWT.NONE) ;
+ }
+ // Then generates a textual representation comment, indenpently of compilation results
+ Comment textualRepresentationComment = null ;
+ List<Comment> allComments = element.getOwnedComments() ;
+ if (!allComments.isEmpty()) {
+ for (Comment comment : allComments) {
+ if (AlfEditorUtils.isATextualRepresentationComment(comment)) {
+ textualRepresentationComment = comment ;
+ }
+ }
+ }
+ if (textualRepresentationComment == null) {
+ // A textual representation comment has to be created
+ textualRepresentationComment = AlfEditorUtils.createTextualRepresentationComment(this.element) ;
+ }
+ textualRepresentationComment.setBody(this.textualRepresentation) ;
+ }
+
+ public boolean getCompileResult() {
+ return this.compileResult ;
+ }
+
+ }
+
+ /**
+ * Adds a textual representation comment to the edit modelObject, if this eObject is a uml Element
+ *
+ * @param graphicalEditPart
+ * @param modelObject
+ * @param newTextualRepresentation
+ */
+ public boolean validate(Element contextElement, String newTextualRepresentation, Object[] args) {
+ TransactionalEditingDomain domain = (TransactionalEditingDomain)EMFHelper.resolveEditingDomain(contextElement) ;
+ ValidateCommand updateCommand = new ValidateCommand(contextElement, newTextualRepresentation, args, domain);
+ domain.getCommandStack().execute(updateCommand) ;
+ return updateCommand.getValidationResult() ;
+ }
+
+ /**
+ * @author CEA LIST
+ *
+ * A command for updating the context UML model
+ */
+ protected class ValidateCommand extends RecordingCommand {
+
+ protected Element element ;
+ protected String textualRepresentation ;
+ protected Object[] args ;
+ protected boolean validationResult = false ;
+
+ public ValidateCommand(Element element, String textualRepresentation, Object[] args, TransactionalEditingDomain domain) {
+ super(domain) ;
+ this.element = element ;
+ this.textualRepresentation = textualRepresentation ;
+ this.args = args ;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor
+ * , org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected void doExecute() {
+ // first tries to compile the textual representation
+ IAlfCompiler alfCompiler = AlfEditorUtils.getAlfCompiler() ;
+ if (alfCompiler != null) {
+ this.validationResult = alfCompiler.validate(element, textualRepresentation, args) ;
+ }
+ else {
+ MessageDialog.open(MessageDialog.ERROR, Display.getCurrent().getActiveShell(), "Validation info", "No registered Alf Compiler", SWT.NONE) ;
+ }
+ }
+
+ public boolean getValidationResult() {
+ return this.validationResult ;
+ }
+
+ }
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/OpenAlfEditorHandler.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/OpenAlfEditorHandler.java
new file mode 100644
index 00000000000..1648696d59a
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/integration/OpenAlfEditorHandler.java
@@ -0,0 +1,151 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.integration;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Activity;
+import org.eclipse.uml2.uml.Element;
+
+public class OpenAlfEditorHandler extends AbstractHandler implements IObjectActionDelegate {
+
+ public OpenAlfEditorHandler() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) {
+ Display current = Display.getCurrent();
+
+ if(current == null) {
+ current = Display.getDefault();
+ }
+ Shell shell = current.getActiveShell();
+
+ if(shell != null) {
+ updateSelectedEObject();
+ } else {
+ // Activator.log.error("impossible to find a shell to open the message dialog", null);
+ }
+
+ return null;
+ }
+
+ /**
+ * Convert each selected elements from the explorator menu, or modeling view
+ * to an EObject and add it to a list
+ *
+ * @return list of EObject
+ */
+ public void updateSelectedEObject() {
+
+ Vector<EObject> currentSelectedEObjects = new Vector<EObject>();
+
+ // Retrieve selected elements
+ IStructuredSelection selection = (IStructuredSelection)PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getSelectionService().getSelection();
+
+
+ Iterator<?> eltIt = (Iterator<?>)selection.iterator();
+
+ while(eltIt.hasNext()) {
+ Object currentObject = eltIt.next();
+
+ // If the object is an edit part, try to get semantic bridge
+ if(currentObject instanceof GraphicalEditPart) {
+ GraphicalEditPart editPart = (GraphicalEditPart)currentObject;
+ if(editPart.getModel() instanceof View) {
+ View view = (View)editPart.getModel();
+ if(view.getElement() instanceof Element) {
+ currentObject = (Element)view.getElement();
+ }
+ }
+ }
+
+ // check whether part of model explorer
+ if(currentObject instanceof IAdaptable) {
+ // modisco ModelElementItem supports IAdaptable (cleaner than cast / dependency with modisco)
+ currentObject = ((IAdaptable)currentObject).getAdapter(EObject.class);
+ }
+
+ // If element is a UML Element
+ if(currentObject instanceof Element) {
+ currentSelectedEObjects.add((EObject)currentObject);
+ if (currentObject instanceof Activity) {
+ new AlfPopupEditor((Element)currentObject, null).openEditor() ;
+ }
+ else {
+ MessageDialog.open(MessageDialog.ERROR, Display.getCurrent().getActiveShell(), "Alf Editor", "The selected element cannot be edited. Current integration only supports Activities.", SWT.NONE) ;
+ }
+ }
+
+ }
+ selectedEObjects = currentSelectedEObjects;
+ }
+
+ /**
+ * Convert each selected elements from the explorator menu, or modeling view
+ * to an EObject and add it to a list
+ *
+ * @return list of EObject
+ */
+ public EObject getSelectedEObject() {
+ if(selectedEObjects.size() > 0) {
+ return selectedEObjects.get(0);
+ }
+ return null;
+ }
+
+ public List<EObject> getSelectedEObjects() {
+ return selectedEObjects;
+ }
+
+ private List<EObject> selectedEObjects;
+
+
+ public void run(IAction action) {
+ // TODO Auto-generated method stub
+ this.execute(null);
+ }
+
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfDescriptionLabelProvider.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfDescriptionLabelProvider.java
new file mode 100644
index 00000000000..c9743045fb4
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfDescriptionLabelProvider.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.labeling;
+
+import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider;
+
+/**
+ * Provides labels for a IEObjectDescriptions and IResourceDescriptions.
+ *
+ * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
+ */
+public class AlfDescriptionLabelProvider extends DefaultDescriptionLabelProvider {
+
+/*
+ //Labels and icons can be computed like this:
+
+ String text(IEObjectDescription ele) {
+ return "my "+ele.getName();
+ }
+
+ String image(IEObjectDescription ele) {
+ return ele.getEClass().getName() + ".gif";
+ }
+*/
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfLabelProvider.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfLabelProvider.java
new file mode 100644
index 00000000000..7987b12916e
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/labeling/AlfLabelProvider.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.labeling;
+
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
+
+import com.google.inject.Inject;
+
+/**
+ * Provides labels for a EObjects.
+ *
+ * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
+ */
+public class AlfLabelProvider extends DefaultEObjectLabelProvider {
+
+ @Inject
+ public AlfLabelProvider(AdapterFactoryLabelProvider delegate) {
+ super(delegate);
+ }
+
+/*
+ //Labels and icons can be computed like this:
+
+ String text(MyModel ele) {
+ return "my "+ele.getName();
+ }
+
+ String image(MyModel ele) {
+ return "MyModel.gif";
+ }
+*/
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/outline/AlfOutlineTreeProvider.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/outline/AlfOutlineTreeProvider.java
new file mode 100644
index 00000000000..11df073da1b
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/outline/AlfOutlineTreeProvider.java
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.alf.ui.outline;
+
+import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider;
+
+/**
+ * customization of the default outline structure
+ *
+ */
+public class AlfOutlineTreeProvider extends DefaultOutlineTreeProvider {
+
+}
diff --git a/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/quickfix/AlfQuickfixProvider.java b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/quickfix/AlfQuickfixProvider.java
new file mode 100644
index 00000000000..c0caed0da9e
--- /dev/null
+++ b/sandbox/Alf/org.eclipse.papyrus.alf.ui/src/org/eclipse/papyrus/alf/ui/quickfix/AlfQuickfixProvider.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.alf.ui.quickfix;
+
+import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
+
+public class AlfQuickfixProvider extends DefaultQuickfixProvider {
+
+// @Fix(MyJavaValidator.INVALID_NAME)
+// public void capitalizeName(final Issue issue, IssueResolutionAcceptor acceptor) {
+// acceptor.accept(issue, "Capitalize name", "Capitalize the name.", "upcase.png", new IModification() {
+// public void apply(IModificationContext context) throws BadLocationException {
+// IXtextDocument xtextDocument = context.getXtextDocument();
+// String firstLetter = xtextDocument.get(issue.getOffset(), 1);
+// xtextDocument.replace(issue.getOffset(), 1, firstLetter.toUpperCase());
+// }
+// });
+// }
+
+}

Back to the top