Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Label expression with condition
Label expression with condition [message #1695825] Tue, 19 May 2015 14:30 Go to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Hello,

In a column, I would like to change the column label according to the eobject features: if there is a string, I want to show something, otherwise, show a generic label. So, I was looking for putting a "if" condition in the label expression. Unfortunately, my expression is not interpreted and my code is pasted in the column.

The condition I put is the following:
[ if (self.goalReference->isEmpty()) ]
no reference
[else]
[self.goalReference.name]
[/if]

This condition/code works using the interpreter. But when I put it in the coilumn expression, it does not work

Any idea how to do that?

Thanks.
Re: Label expression with condition [message #1695842 is a reply to message #1695825] Tue, 19 May 2015 17:19 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

It seems weird that this expression works in the interpreter as an
acceleo expression should be surrounded by [ /]. Anyway, Acceleo
provides the service "if" and should be used in a single expression as
follows:
[if(self.goalReference->isEmpty()) then '' else self.goalReference.name
endif/]

Note that if goalReference is a multivalued reference (as you use the
operation ->isEmpty) "self.goalReference.name" will return the
concatenation of the name of each referenced elements.

Regards,
Steve

Le 19/05/2015 16:30, Julien Delange a écrit :
> Hello,
>
> In a column, I would like to change the column label according to the
> eobject features: if there is a string, I want to show something,
> otherwise, show a generic label. So, I was looking for putting a "if"
> condition in the label expression. Unfortunately, my expression is not
> interpreted and my code is pasted in the column.
>
> The condition I put is the following:
> [ if (self.goalReference->isEmpty()) ]
> no reference
> [else]
> [self.goalReference.name]
> [/if]
>
> This condition/code works using the interpreter. But when I put it in
> the coilumn expression, it does not work
>
> Any idea how to do that?
>
> Thanks.


--
Steve Monnier - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Label expression with condition [message #1695844 is a reply to message #1695842] Tue, 19 May 2015 17:39 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Hi Steve,

I tried the solution but it does not work and it returns nothing - maybe this is because I am using the nightly build? is there any update on the acceleo language that would explain why the first solution worked first and your suggestion does not work, either in the interpreter or in the label expression?
Re: Label expression with condition [message #1695898 is a reply to message #1695844] Wed, 20 May 2015 07:56 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

I do not think that this is caused by the version being a nightly build
(but I have been wrong before). The Acceleo language is pretty stable
and the nightly build should not be that different from an official
release. Why do you use a nightly build instead of a stable release?
Anyway, can you describe a little bit how is made your metamodel to work
this out? Is "goalReference" a multivalued reference? What is its parent
Metaclass? What is the type of this reference.

Regards,
Steve

Le 19/05/2015 19:39, Julien Delange a écrit :
> Hi Steve,
>
> I tried the solution but it does not work and it returns nothing - maybe
> this is because I am using the nightly build? is there any update on the
> acceleo language that would explain why the first solution worked first
> and your suggestion does not work, either in the interpreter or in the
> label expression?


--
Steve Monnier - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Label expression with condition [message #1705030 is a reply to message #1695898] Tue, 11 August 2015 14:02 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Hi

I have same problem. I set label expression to 'feature:isIdentifier' and I get either 'false' or 'true' string. That's right.

But I see nothing, when I set label expression to
[if (self.isIdentifier) then 'qwe' else 'asd' endif/]
Re: Label expression with condition [message #1705042 is a reply to message #1705030] Tue, 11 August 2015 15:22 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Denis

Le 11/08/2015 16:02, Denis Nikiforov a écrit :
> [if (self.isIdentifier) then 'qwe' else 'asd' endif/]

Could try [(if (self.isIdentifier) then 'qwe' else 'asd' endif)/] ?

Note the () around the if .. endif: this force Acceleo to see it as an
OCL if.

This might indicate an issue in the Sirius Acceleo bridge.

Regards


--
Maxime - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Label expression with condition [message #1705094 is a reply to message #1705042] Wed, 12 August 2015 06:29 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
Hi

It doesn't help Sad Here is a test project:
https://github.com/AresEkb/anchor

My odesign file:
https://github.com/AresEkb/anchor/blob/master/anchor.design/description/anchor.odesign

And test model:
https://github.com/AresEkb/anchor/tree/master/anchor.tests/model

Even ['qwe'/] returns nothing...
Re: Label expression with condition [message #1705368 is a reply to message #1705094] Fri, 14 August 2015 08:12 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
When I set "Label Expression" to [self.toString()/] I get the following exception:

------
STATUS
------
pluginId            org.eclipse.sirius.common.acceleo.mtl
pluginVersion       3.0.0.201506090807
code                0
severity            4
message             Argument types mismatch for module element dynamicModuleQuery6.
fingerprint         7bec1f74

Exception:org.eclipse.acceleo.engine.AcceleoEvaluationException: Argument types mismatch for module element dynamicModuleQuery6.
	 at org.eclipse.acceleo.engine.generation.AcceleoEngine.doEvaluate(AcceleoEngine.java:401)
	 at org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate(AcceleoEngine.java:203)
	 at org.eclipse.acceleo.engine.service.AcceleoEvaluationTask.evaluateQuery(AcceleoEvaluationTask.java:122)
	 at org.eclipse.acceleo.engine.service.AcceleoEvaluationTask.call(AcceleoEvaluationTask.java:291)
	 at org.eclipse.sirius.common.acceleo.mtl.business.internal.interpreter.DynamicAcceleoModule.evaluate(DynamicAcceleoModule.java:536)
	 at org.eclipse.sirius.common.acceleo.mtl.business.internal.interpreter.AcceleoMTLInterpreter.internalEvaluate(AcceleoMTLInterpreter.java:1125)
	 at org.eclipse.sirius.common.acceleo.mtl.business.internal.interpreter.AcceleoMTLInterpreter.evaluateString(AcceleoMTLInterpreter.java:679)
	 at org.eclipse.sirius.tools.internal.interpreter.ODesignGenericInterpreter.evaluateString(ODesignGenericInterpreter.java:161)
	 at org.eclipse.sirius.diagram.business.internal.metamodel.helper.DiagramElementMappingHelper.computeLabel(DiagramElementMappingHelper.java:114)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramElementSynchronizer.computeLabel(DDiagramElementSynchronizer.java:833)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramElementSynchronizer.refreshCenterLabel(DDiagramElementSynchronizer.java:482)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramElementSynchronizer.refresh(DDiagramElementSynchronizer.java:416)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.createEdgeCandidates(DDiagramSynchronizer.java:1391)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.refreshEdgeMapping(DDiagramSynchronizer.java:1312)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.processEdgeMappingsRefresh(DDiagramSynchronizer.java:498)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.refreshOperation(DDiagramSynchronizer.java:427)
	 at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.refresh(DDiagramSynchronizer.java:352)
	 at org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.refresh(DDiagramSynchronizer.java:91)
	 at org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.refresh(DiagramDialectServices.java:249)
	 at org.eclipse.sirius.business.internal.dialect.DialectManagerImpl.refresh(DialectManagerImpl.java:118)
	 at org.eclipse.sirius.business.api.dialect.command.RefreshRepresentationsCommand.doExecute(RefreshRepresentationsCommand.java:124)
	 at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
	 at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:119)
	 at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	 at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
	 at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
	 at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	 at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	 at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.launchRefresh(DDiagramEditorImpl.java:1289)
	 at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.access$2(DDiagramEditorImpl.java:1261)
	 at org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl$2.run(DDiagramEditorImpl.java:636)
	 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

------
REPORT
------
comment             
eclipseBuildId      4.5.0.I20150603-2000
eclipseProduct      org.eclipse.epp.package.modeling.product
javaRuntimeVersion  1.8.0_25-b18
osgiWs              win32
osgiOs              Windows7
osgiOsVersion       6.1.0
osgiArch            x86_64
logMessage          false
ignoreSimilar       false

-------
BUNDLES
-------
name                org.eclipse.acceleo.engine
version             3.6.0.201506080954

name                org.eclipse.core.commands
version             3.7.0.v20150422-0725

name                org.eclipse.core.jobs
version             3.7.0.v20150330-2103

name                org.eclipse.emf.transaction
version             1.9.0.201506010221

name                org.eclipse.emf
version             2.6.0.v20150601-0402

name                org.eclipse.emf.workspace
version             1.5.1.201506010221

name                org.eclipse.sirius
version             3.0.0.201506090807

name                org.eclipse.sirius.common.acceleo.mtl
version             3.0.0.201506090807

name                org.eclipse.sirius.common
version             3.0.0.201506090807

name                org.eclipse.sirius.diagram
version             3.0.0.201506090807

name                org.eclipse.sirius.diagram.ui
version             3.0.0.201506090807
Re: Label expression with condition [message #1705369 is a reply to message #1705368] Fri, 14 August 2015 08:35 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 343
Registered: August 2013
Senior Member
I've got it. It seems that here is a simillar bug: https://www.eclipse.org/forums/index.php/t/781784/
When I run "Runntime Eclispe Application" from my workspace everithing works fine.
Re: Label expression with condition [message #1775002 is a reply to message #1695842] Mon, 23 October 2017 12:02 Go to previous messageGo to next message
tummalapalli bnvv kirankumar is currently offline tummalapalli bnvv kirankumarFriend
Messages: 1
Registered: October 2017
Junior Member
Could someone help, How to use elseif statement

I tried using

aql:[if(self.Name='ABC') then ok1' elseif(self.Name='abc') then 'ok2' else 'wrong' endif/]

but it's not working
Re: Label expression with condition [message #1775059 is a reply to message #1775002] Tue, 24 October 2017 09:14 Go to previous message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

You are mixing AQL (aql:) and Acceleo syntax ([/]).
See the documentation https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html to know more.

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Call Arrange All (Arrange Selection) when creating an edge
Next Topic:Change help expressions in Properties View in Sirius Diagram
Goto Forum:
  


Current Time: Fri Mar 29 09:39:58 GMT 2024

Powered by FUDForum. Page generated in 0.03172 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top