[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] integer arrays

Hi,

I need to use one and two dimensional integer arrays in my application and I would appreciate it if anyone could advise me of the best way to do this.

What I am trying to to is define arrays to minimise any custom programming that I have to do in order to edit these parameters and to serialise them to XML.

I have done some experiments, explained below, but none of them give the ideal result so I would appreciate ideas about how I could improve this.

My first attempt is to define an array like this:

/**
* @model containment="true"
*/
int[] getOneDArray();

This generates an entry in the model.ecore file:
IntArray [int[]]
I assume this entry means that I have to write the code for this type myself.


When I generate the code it has the following error:
cannot cast from int[] to InternalEObject
this seems to be because I set containment="true" so I tried it without:

/**
* @model
*/
int[] getOneDArray();
	
This generates an entry in the model.ecore file:
<.> IntArray [int[]]

The code generated OK, but when I used the application it just treated this like a single string rather than an integer array.
Since editing the parameter and serialising it to XML needs the values in string form I thought it would be easier to just treat it as an array of strings and then convert to array when I need to use it in my application. So I tried this:


/**
* @model
*/
EList<String> getStringArray();

This works as I want, of course I will have to write code to validate user input and also do the Integer.parseInt when I need to use. The thing that concerns me more is that the UML diagram will not correctly show that this is is an integer array. Also this seems to give a mismatch between the model required for the application and the diagram.

An even more difficult question is how to work with two dimensional arrays. This won't work:

/**
* @model
*/
int[][] getTwoDArray();

and this won't work either:

/**
* @model
*/
EList<EList<String>> getTwoDArray();	

The only way that I can to do this is to intersperse a complete new class called, say, 'row' then I can have a single dimensional array of rows, and each row contains a a single dimensional array of elements. Bus again this seems to give a mismatch between the model required for the application and the diagram.

The other thing that I would like to do is show these arrays directly in the diagram. Is it possible to put a jface TableViewer directly in the rectangular box in the diagram?

Martin