Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » content assist/cross reference/scoping(I want content assist to limit cross referencing via scoping.)
content assist/cross reference/scoping [message #555729] Fri, 27 August 2010 22:53 Go to next message
Dennis  is currently offline Dennis Friend
Messages: 19
Registered: August 2010
Junior Member
I have created two domain specific languages: MyWorld.xtext and MyVacations.xtext

Based on MyWorld grammar, I created a file called Europe.MyWorld (see below).
Europe {
   Germany
   England
}


Likewise, I created two more files: NorthAmerica.MyWorld and Asia.MyWorld.

NorthAmerica {
   USA
   Canada
}

Asia {
   Japan
   China
}


Furthermore, grammar MyVacations cross references to grammar MyWorld.

In MyVacations.xtext:
import "platform:/resource/org.xtext.myworld/src-gen/org/xtext/myworld/MyWorld.ecore" as myworld
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

....

MyVacation hidden():element=[myworld::location]'.'attribute=[myworld::country];

....



Content assist will automatically cross reference ALL three files (Europe.MyWorld, NorthAmerica.MyWorld, Asia.MyWorld).

So far so good. For example, content assist will prompt <x> for Europe, NorthAmerica and Asia. And <y> for ALL the countries.

My summer vacation will be in <x>.  The country will be in <y>.


Here's my question:
If my summer vacation is in Europe, can content assist prompt Germany and England which belongs to Europe and not the other countries?

In other words, I want to cross reference to Europe but to exclude North America and Asia.

Or to cross reference to Europe and Asia but to exclude North America.

My goal is not to have content assist to cross reference ALL the MyWorld files and to prompt ALL the available countries.

Is it possible to have content assist to limit cross referencing via scoping? I hope I make my question clear. Any help would be greatly appreciated.
Re: content assist/cross reference/scoping [message #555752 is a reply to message #555729] Sat, 28 August 2010 08:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

basically this is what scoping is for.

to make only the countries within the chosen continent visible is very easy:

with grammars like:

grammar org.xtext.example.myworld.MyWorld with org.eclipse.xtext.common.Terminals

generate myWorld "http://www.xtext.org/example/myworld/MyWorld"

World:
	continents+=Continent*
;

Continent:
	name=ID "{"
		countries+=Country*
	"}"
;

Country:
	name=ID
;


grammar org.xtext.example.myvacation.MyVacation with org.eclipse.xtext.common.Terminals

generate myVacation "http://www.xtext.org/example/myvacation/MyVacation"

import "platform:/resource/org.xtext.example.myworld/src-gen/org/xtext/example/myworld/MyWorld.ecore" as myworld

Model:
	vacations+=Vacation*;
	
Vacation:
	"My" "summer" "vacation" "will" "be" "in" continent=[myworld::Continent] "."  "The" "country" "will" "be" "in" country=[myworld::Country] "."
;


it's just this threeliner:

public class MyVacationScopeProvider extends AbstractDeclarativeScopeProvider {
	
	public IScope scope_Vacation_country(Vacation vacation, EReference ref) {
		return Scopes.scopeFor(vacation.getContinent().getCountries());
	}

}


to do the same for

Quote:

Or to cross reference to Europe and Asia but to exclude North America.



which is also possible by scoping you have to be a bit more precise on what crieria you to want to do the restriction.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: content assist/cross reference/scoping [message #556053 is a reply to message #555752] Mon, 30 August 2010 16:59 Go to previous messageGo to next message
Dennis  is currently offline Dennis Friend
Messages: 19
Registered: August 2010
Junior Member
Thanks for the example.

What I reallly want is to limit the continents. In other words, if there are thousands of continents, I want to be able to select a subset of continents to choose from. Once a continent is selected, scoping will work it's magic to prompt for its countries.

The example code you gave was 2 levels deep: getContinent and getCountries.
return Scopes.scopeFor(vacation.getContinent().getCountries());


I think I will need to have 3 levels deep: getLimitedContinentList getContinent and getCountries. Can it be done? Would you give more examples? Thanks in advance!
Re: content assist/cross reference/scoping [message #556074 is a reply to message #556053] Mon, 30 August 2010 17:38 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you may want separate the two concerns visibility (scoping) and proposals, i.e. although all 3000 continents are valid, visible and can be manually entered without linking error (via scoping), you override the proposal function so that it is not based on scoping (as it is by default) but only proposes a subset (you somehow calculate manually).

In the generated proposal provider there should be a method something like completeVacation_Continent that you can override to construct your own list of proposals. See the documentation and various threads of this forum as to customised completion proposals.
Re: content assist/cross reference/scoping [message #556102 is a reply to message #556074] Mon, 30 August 2010 19:08 Go to previous messageGo to next message
Dennis  is currently offline Dennis Friend
Messages: 19
Registered: August 2010
Junior Member
Hi,

Unfortunately, the list of proposals is not based on formulas but it will need to be dynamically built.

What I mean is to predefine a subset of continents ahead of time dynamically.

For example, I want to vacation in Europe or Asia but I have not made up my mind yet . To do that, I can specify a subset of continents ahead of time. At this time, I have not decided exactly what continents but I know it will be either in Europe or Asia, and not South America, North America, or somewhere else.

I can only know what continent when I type "My summer vacation will be in .... (see below)

[Proposed Continents: Europe, Asia]
My summer vacation will be in Asia.  The country will be in Japan.


Once Asia is typed in, content assist will only prompt Japan or China.

As you recall, going back to my original SELECT SQL grammer, I want to implement scoping for JOIN tables inside a query.
I have successfully implemented column scoping. When I type in a table name, content assist will prompt me for its column names.

If I have thousand of table names, I don't want content assist to prompt me for thousands of table names.
Because of my limited knowledge of xtext and Java programming experience, it is not likely that I am able to have content assist to prompt me for table1, table2
and table3 inside a query (see example below).

Namespace Blah{

    Query TestBlah{

	[RETURN: table1.column1]

        FROM table1
        INNER JOIN table2 ON table1.t1 = table2.t2
        LEFT OUTER JOIN table3 ON table1.t1 = table3.t3


    }
}


What I can possibly do is to try to explicity list all the tables that I would want to use in a query ahead of time.

Like:
[Posposed Tables: table1, table2, table3 ]


If I can change my grammar (RETURN, FROM, INNER JOIN, LEFT OUTER JOIN) to select tables from [Proposed Tables], content assist will now
be able to prompt me for only three tables: table1, table2 and table3.

I hope you finally understand what I want to accomplish.
Re: content assist/cross reference/scoping [message #556110 is a reply to message #556102] Mon, 30 August 2010 19:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

if you do it explicitly its all the same as it is for countries

grammar org.xtext.example.myvacation.MyVacation with org.eclipse.xtext.common.Terminals

generate myVacation "http://www.xtext.org/example/myvacation/MyVacation"

import "platform:/resource/org.xtext.example.myworld/src-gen/org/xtext/example/myworld/MyWorld.ecore" as myworld

Model:
	vacations+=Vacation*;
	
Vacation:
	"[" proposal=VacationProposal "]"
	"My" "summer" "vacation" "will" "be" "in" continent=[myworld::Continent] "."  "The" "country" "will" "be" "in" country=[myworld::Country] "."
;

VacationProposal:
	"Proposed" "Continents" ":" poposedContentents+=[myworld::Continent] ("," poposedContentents+=[myworld::Continent])*
;


	public IScope scope_Vacation_continent(Vacation vacation, EReference ref) {
		return Scopes.scopeFor(vacation.getProposal().getPoposedContentents());
	}


and with

[ Proposed Continents : Europe, Asia]
My summer vacation will be in


you will only get Europe and Asia as continent.

so do you want to do it explicitly or implcitly and if implicitly on which criteria,

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 30 August 2010 20:00]

Report message to a moderator

Re: content assist/cross reference/scoping [message #556113 is a reply to message #556110] Mon, 30 August 2010 20:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Here is a sample for an implicit / code based filtering

public class MyVacationScopeProvider extends AbstractDeclarativeScopeProvider {

	public IScope scope_Vacation_country(Vacation vacation, EReference ref) {
		return Scopes.scopeFor(vacation.getContinent().getCountries());
	}

	public IScope scope_Vacation_continent(Vacation vacation, EReference ref) {
		IScope all = delegateGetScope(vacation, ref);
		return new SimpleScope(Iterables.filter(all.getAllContents(), new Predicate<IEObjectDescription>() {

			@Override
			public boolean apply(IEObjectDescription input) {
				if ("Asia".equals(input.getName()) || "Europe".equals(input.getName())) {
					return true;
				}
				return false;
			}
		}));
		
	}
	
}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: content assist/cross reference/scoping [message #556116 is a reply to message #556110] Mon, 30 August 2010 20:55 Go to previous messageGo to next message
Dennis  is currently offline Dennis Friend
Messages: 19
Registered: August 2010
Junior Member
Hi,

You have demonstrated to me how to do it explicitly in your code. Thanks so much.

Both you and Alex are great help!

Of course, I want to do it implicitly.

If you go back to my SQL example posted above, the criteria is the table names from the JOINS.

By JOINS, I mean table1 from "FROM", table2 from "INNER" JOIN" and table3 from "LEFT" "OUTER" "JOIN".

If I have another table join, "LEFT" "OUTER" "JOIN" table4, table4 should be dynamically included in the scoping.

If there is no solution, my workaround is to hardcode the possible table names ahead of time.

Like:
[Posposed Tables: table1, table2, table3, table4 ]


If there is a way to do it dynamically, it would be wonderful!
Re: content assist/cross reference/scoping [message #556118 is a reply to message #556116] Mon, 30 August 2010 20:59 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

if you want to put all tables that are involved in the join on the scope this is explicit and works the same as for the columns/countries.

So just extract all tables from the joins, put them on a list, and create the scope from it,

Just think of

[Posposed Tables: table1, table2, table3, table4 ]


as

table1 JOIN table2 JOIN table3 JOIN table4


it might a bit more complicated depending on your metamodel and maybe (linkling) order but this should not be unsolveable.


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 30 August 2010 21:06]

Report message to a moderator

Previous Topic:Problem referencing other Files during clean all
Next Topic:Integrate grammar/generator developed in Xtext into Eclipse
Goto Forum:
  


Current Time: Tue Apr 23 12:05:11 GMT 2024

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

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

Back to the top