eclipse-ocl / org.eclipse.ocl

Eclipse Public License 2.0
0 stars 0 forks source link

[console] Overhaul the OCL Example #357

Open eclipse-ocl-bot opened 2 days ago

eclipse-ocl-bot commented 2 days ago

| --- | --- | | Bugzilla Link | 259922 | | Status | NEW | | Importance | P3 enhancement | | Reported | Jan 04, 2009 18:38 EDT | | Modified | May 27, 2011 07:54 EDT | | Version | 1.2.0 | | Blocks | 318358 | | Reporter | Christian Damus |

Description

The current "Interactive OCL Console" example has several deficiencies as a demonstration of the client side of the OCL API (the provider side is already sufficiently demonstrated by the Ecore and UML metamodel bindings):

A new example is warranted to address these shortcomings. It is also a good opportunity, since the examples feature will be rejigged, to deliver the generated *.edit plug-ins as discussed in bug 196973.

eclipse-ocl-bot commented 2 days ago

By Nicolas Rouquette on Jan 11, 2009 20:44

+1: I look forward to this functionality!

eclipse-ocl-bot commented 2 days ago

By Christian Damus on Jan 11, 2009 23:15

Created attachment 122227 First cut of a new console example

Attached the firt cut of a new "console" example.

The "console" consists of three views: Environment Browser, OCL Input, and OCL Results. All of these views can be opened from the "Window -> Show View" menu (of course). The Ecore and UML model editors also have new "Show OCL Console" actions that open the OCL Input and Environment Browser views.

Environment Browser

In this view, the user creates and manages OCL environments. Each environment is independent of the others and is reusable in any user action. Most actions are performed in the currently selected environment.

The "New Environment" action creates a new OCL environment for the target metamodel most appropriate to the currently select EObject. This selection is determined from the active editor, if possible, otherwise some other workbench part. Currently, support for Ecore and UML metamodels is plugged in via extensions in the two plug-ins included in the attachment.

Environments are distingushed visually using the icon for the Package concept of their target metamodel. Any number of environments can be created.

The browser organizes the contents of each environment into folders, grouping:

(I'm currently unsure of how to sensibly define variables, or even whether it is interesting, so that folder doesn't do anything)

One convenient way to create Constraints and Definitions in an OCL environment is to load a *.ocl document (text, not XMI) using the action in the environment browser view.

The Environment Browser is connected to the Properties View. All elements shown in the browser have names that can be edited in the property sheet or in-line in the tree (only folders can't be edited).

For OCL environment nodes, the Properties view shows the generic and metamodel-specific properties of the environment, which are mostly parsing and evaluation options that should be familiar from the API. Thus, the "console" now provides access to the target meta-level via the Properties view, as well as such important details as root EClass and, for UML, the evaluation mode. Parsing and evaluation options can be changed at any time; they only affect future parsing and/or evaluation actions.

The default modeling level is "User Model" (M1), useful for developing model constraints.

OCL environments can be deleted in the usual way, as can the elements within them: constraints, queries, and definitions.

OCL Input View

This view simply has a text area in which to enter OCL text, and a message area below it that shows errors when necessary. Any kind of OCL text is accepted, as follows:

Unlike the old example, the OCL Input view no longer clears its contents on successful parse/evaluation of the OCL text.

The OCL Environments view acts like a random-access history for the OCL Input view. To recall any constraint, definition, or query that was entered via this view, simply select the element in the OCL Environments view, and the original text will be set in the OCL Input view. This is handy for creating additional OCL elements that are similar to previously entered elements.

OCL Results

The OCL results view is shown whenever a query expression is evaluated. The presentation of results varies by the kind of result:

There are a few ways to show results in this view:

Outstanding TODO Items

The list includes at least:

:compression: ocl-example.zip

eclipse-ocl-bot commented 2 days ago

By Nicolas Rouquette on Jan 12, 2009 01:50

Created attachment 122237 Patch to the old OCL example interpreter plugin.properties file

:notepad_spiral: old.ocl.examples.interpreter.plugin.properties.patch

eclipse-ocl-bot commented 2 days ago

By Nicolas Rouquette on Jan 12, 2009 02:04

Wow! This is amazing!

I have 4 comments.

1) The Query folder shows the first line of a multi-line query expression typed in the OCL Input window.\ This can be useful to give a useful mnemonic to a complex query, e.g.:

-- who am I?\ self.qualifiedName

The query folder only shows "-- who am I?"

2) confusion between old & new OCL console.

I suggest changing the properties of the old console to avoid having two "Show OCL Console" menus...\ (see patch)

3) loading *.ocl

What is the grammar for OCL documents?

I used the example in the org.eclipse.ocl.uml.tests plugin but I didn't get far...\ I open a UML model in the UML Editor and open the OCL console.\ As I mentioned, I can issue queries, so far so good...\ But, loading any OCL document brings this exception:

java.lang.NullPointerException\ at org.eclipse.ocl.util.OCLUtil$1.tryLookupClassifier(OCLUtil.java:120)\ at org.eclipse.ocl.parser.AbstractOCLAnalyzer.lookupClassifier(AbstractOCLAnalyzer.java:4240)\ at org.eclipse.ocl.parser.AbstractOCLAnalyzer.classifierContextDeclCS(AbstractOCLAnalyzer.java:1237)\ at org.eclipse.ocl.parser.AbstractOCLAnalyzer.contextDeclCS(AbstractOCLAnalyzer.java:734)\ at org.eclipse.ocl.parser.AbstractOCLAnalyzer.packageDeclarationCS(AbstractOCLAnalyzer.java:697)\ at org.eclipse.ocl.parser.AbstractOCLAnalyzer.packageDeclarationCS(AbstractOCLAnalyzer.java:713)\ at org.eclipse.ocl.parser.AbstractOCLAnalyzer.documentCS(AbstractOCLAnalyzer.java:642)\ at org.eclipse.ocl.parser.OCLAnalyzer.parseOCLDocument(OCLAnalyzer.java:182)\ at org.eclipse.ocl.OCL.parse(OCL.java:258)\ at org.eclipse.ocl.examples.console.util.OCLConsoleUtil.loadOCLDocument(OCLConsoleUtil.java:205)\ at org.eclipse.ocl.examples.console.actions.LoadDocumentAction.run(LoadDocumentAction.java:91)

In the debugger, I noticed something odd:

public static void loadOCLDocument(IWorkbenchPartSite site, OCLInput input) {\
    OCLNode node = getSelectedOCLNode(site);\
    OCL ocl = node.element();\
    \
    try {\
        ocl.parse(input); // here,  ocl.environmentFactory.umlMetamodel == null.

It seems to me that the ocl env should know what is our metamodel...\ Who has the responsibility for initializing the metamodel?

4) load/save for both OCL documents & OCL environments

With a combination of loaded OCL documents & OCL content I can edit with the console, the only thing missing is to be able to save the whole thing & reload it later.

eclipse-ocl-bot commented 2 days ago

By Christian Damus on Jan 13, 2009 13:23

(In reply to comment #3)

Created an attachment (id=122237) Patch to the old OCL example interpreter plugin.properties file

Thanks. That's a good idea.

(In reply to comment #4)

Wow! This is amazing!

I have 4 comments.

1) The Query folder shows the first line of a multi-line query expression typed in the OCL Input window.

Yes. You can alse edit the name post facto.

This can be useful to give a useful mnemonic to a complex query, e.g.:

-- who am I? self.qualifiedName

The query folder only shows "-- who am I?"

Is that a bad thing? Newlines are always awkward to deal with in flat labels.

3) loading *.ocl

What is the grammar for OCL documents?

Section 12.12 of the OCL Specification.

In the debugger, I noticed something odd:

public static void loadOCLDocument(IWorkbenchPartSite site, OCLInput input) { OCLNode node = getSelectedOCLNode(site); OCL ocl = node.element();

try { ocl.parse(input); // here, ocl.environmentFactory.umlMetamodel == null.

The UMLOCLProvider ensures that the UML metamodel and its dependencies are loaded in your resource set. You should actually see them load in the *.uml editor.

It seems to me that the ocl env should know what is our metamodel... Who has the responsibility for initializing the metamodel?

The UML environment knows about it and loads it when and if it is needed, but in this particular case, something else than the environment is looking for it. That's why the UMLOCLProvider loads it proactively.

Try debugging the UMLOCLProvider ...

4) load/save for both OCL documents & OCL environments

With a combination of loaded OCL documents & OCL content I can edit with the console, the only thing missing is to be able to save the whole thing & reload it later.

Heh heh ... yes. I was thinking of creating a workspace save participant. However, the problem is that the UML environment needs a resource-set context in which to load models (unlike the Ecore environment). I would have to figure out a way to re-connect a UML environment to a particular *.uml editor's resource set on start-up.

eclipse-ocl-bot commented 2 days ago

By Nicolas Rouquette on Jan 15, 2009 13:44

Christian,

Showing only the first line of a multi-line expression is a good thing for the OCLEnvironment view.\ Taking advantage of this feature (accidental luck or intentional wisdom) enhances the usability of the OCLEnvironment view.

Following your suggestion, I tracked down the problem where the result of org.eclipse.ocl.examples.console.uml.UMLOCLProvider.createEnvironmentFactory(EObject)\ is a UMLEnvironmentFactory object with a null umlMetamodel property.

I open a metamodel in the UMLEditor (e.g., fUML from the spec: http://www.omg.org/spec/FUML)

a) If I select the UML resource and in the OCLEnvironment view click on the "New Environment" button, I get an error:

"Cannot determine a metamodel context for the environment. Please select an EMF model element in an editor or view.

This error happens when the list of environments in the view is empty.\ When I have environments in the OCLEnvironment view, it seems that I can create a new OCLEnvironment \ regardless of whether I select the resource of a model element in the UMLEditor.\ I haven't tracked down the peculiar state responsible for this behavior distinction.

b) This time, I selected a model element.\ The relevant stack trace is this:

AdapterFactoryEditingDomain$AdapterFactoryEditingDomainResourceSet(ResourceSetImpl).getResource(URI, boolean) line: 371 // step 3\ OCLUMLUtil.getUMLMetamodel(ResourceSet) line: 488 // step 2\ UMLOCLProvider.createEnvironmentFactory(EObject) line: 83 // step 1\ NewEnvironmentAction.createOCL() line: 97 \ NewEnvironmentAction.run() line: 67 \ NewEnvironmentAction(Action).runWithEvent(Event) line: 498

At step 1, the UMLOCLProvider has created a new UMLEnvironmentFactory whose umlMetamodel attribute is null. \ The idea is that ECore.resolveAll(...) should be setting the umlMetamodel attribute.

At step 2, the OCLUMLUtil makes sure that the resource set includes a resource for the UML metamodel

Resolving the UML metamodel seems to be the responsibility of the UMLEnvironment itself but this is a protected API.

if org.eclipse.ocl.uml.UMLEnvironmentFactory.getUMLMetamodel() becomes public (see attached patch), \ then this problem has an elegant solution as shown below:

public EnvironmentFactory<Package, Classifier, Operation, Property, EnumerationLiteral, Parameter, State, CallOperationAction, SendSignalAction, Constraint, Class, EObject> createEnvironmentFactory(\
        EObject context) {

    UMLEnvironmentFactory result;\
    Resource contextRes = context.eResource();

    if ((contextRes != null) && (contextRes.getResourceSet() != null)) {\
        result = new UMLEnvironmentFactory(contextRes.getResourceSet());\
    } else {\
        result = new UMLEnvironmentFactory();\
    }

    // ensure that we have the UML metamodel loaded, and all of its\
    // dependencies\
    EcoreUtil.resolveAll(result.getUMLMetamodel());

    return result;\
}
eclipse-ocl-bot commented 2 days ago

By Nicolas Rouquette on Jan 15, 2009 13:45

Created attachment 122707 change visibility from protected to public

:notepad_spiral: UMLEnvironmentFactory.getUMLMetamodel.patch

eclipse-ocl-bot commented 2 days ago

By Nicolas Rouquette on Jan 22, 2009 12:33

Quitting the workbench can induce SWT exceptions:

org.eclipse.swt.SWTException: Widget is disposed\ at org.eclipse.swt.SWT.error(SWT.java:3827)\ at org.eclipse.swt.SWT.error(SWT.java:3742)\ at org.eclipse.swt.SWT.error(SWT.java:3713)\ at org.eclipse.swt.widgets.Widget.error(Widget.java:463)\ at org.eclipse.swt.widgets.Widget.getDisplay(Widget.java:578)\ at org.eclipse.ocl.examples.console.tree.AbstractTreeNode.packViewerLater(AbstractTreeNode.java:94)\ at org.eclipse.ocl.examples.console.tree.AbstractTreeNode.update(AbstractTreeNode.java:90)\ at org.eclipse.ocl.examples.console.tree.EObjectNode$RefreshAdapter.notifyChanged(EObjectNode.java:123)\ at org.eclipse.emf.common.notify.impl.BasicNotifierImpl$EAdapterList.didRemove(BasicNotifierImpl.java:95)\ at org.eclipse.emf.common.util.BasicEList.didClear(BasicEList.java:260)\ at org.eclipse.emf.common.util.BasicEList.clear(BasicEList.java:1000)\ at org.eclipse.emf.common.notify.impl.BasicNotifierImpl$EAdapterList.clear(BasicNotifierImpl.java:171)\ at org.eclipse.emf.ecore.resource.impl.ResourceImpl.unloaded(ResourceImpl.java:1559)\ at org.eclipse.emf.ecore.resource.impl.ResourceImpl.doUnload(ResourceImpl.java:1618)\ at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doUnload(XMLResourceImpl.java:505)\ at org.eclipse.emf.ecore.resource.impl.ResourceImpl.unload(ResourceImpl.java:1633)\ at org.eclipse.ocl.AbstractTypeResolver.dispose(AbstractTypeResolver.java:1068)\ at org.eclipse.ocl.AbstractEnvironment.dispose(AbstractEnvironment.java:1168)\ at org.eclipse.ocl.OCL.dispose(OCL.java:742)

There is a simple fix in console.tree.AbstractTreeNode:

original:

protected void packViewerLater() {\
    viewer.getControl().getDisplay().asyncExec(new Runnable() {\
        \
        public void run() {\
            // text changes affect width\
            viewer.getTree().getColumns()[0].pack();\
        }\
    });\
}

modified:

protected void packViewerLater() {\
    final Control control = viewer.getControl();\
    final Tree tree = viewer.getTree();\
    \
    if (control.isDisposed() || tree.isDisposed())\
        return;\
    \
    control.getDisplay().asyncExec(new Runnable() {\
        \
        public void run() {\
            // text changes affect width\
            tree.getColumns()[0].pack();\
        }\
    });\
}
eclipse-ocl-bot commented 2 days ago

By Christian Damus on Feb 09, 2009 08:46

Adding Rich to cc, as this bug intends to obsolete the console recently incorporated into the DSL Toolkit.

eclipse-ocl-bot commented 2 days ago

By Ed Willink on Aug 03, 2009 03:16

This should be generalised to work with the OCL editor.

Perhaps:

While editing the OCL constraints on a meta-model, DND a user model to create an additional editor sheet and auto-activate the OCL Console, allowing evaluations on the user model exploiting the full OCL constraints.

eclipse-ocl-bot commented 2 days ago

By Adolfo Sanchez-Barbudo Herrera on Aug 03, 2009 08:46

Hi Ed,

I agree that we could make OCL take part of the new UI feature. Your proposal sounds really promising, although I would raise a different bugzilla for it, so that we have one (this) bug to move (and improve) the interpreter as part of the OCL UI and different one which would integrate OCL Editor and the OCL console.

What do you think ?

Cheers,\ Adolfo.

eclipse-ocl-bot commented 2 days ago

By Ed Willink on Aug 03, 2009 14:55

I think it's too soon for another Bugzilla.

Someone will take on upgrading the example and pick as many ideas as practical. I thbink we then raise Bugzillas for the residue.