[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Re: Empty properties view in editor when using a ecore model with subpackages
|
I finally found a way to solve the problem.
For the records, here is a solution (there is certainly a better way to
handle this).
Assuming that we want to design a diagram editor for an ecore model
(called example) which contains one toplevel package (top) and two
subpackages (sub1, sub2).
The problem stems from the fact that the TopItemProvider class generated
in the example.edit plugin cannot find ItemProvider classes for classes
that do not belong to the top package.
The solution consist in hacking the TopItemProvider generated java code
so as to make the subpackages classes visible to the
ItemProviderAdapter. This can be done by modifying the code as follows :
1) Add a field to store the subpackages ItemProviderAdapter factories
and Modify the constructor as follows :
protected static AdapterFactoryImpl[] subPackageFactories;
/**
* This constructs an instance.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public DatapathItemProviderAdapterFactory() {
supportedTypes.add(IEditingDomainItemProvider.class);
supportedTypes.add(IStructuredItemContentProvider.class);
supportedTypes.add(ITreeItemContentProvider.class);
supportedTypes.add(IItemLabelProvider.class);
supportedTypes.add(IItemPropertySource.class);
subPackageFactories = new AdapterFactoryImpl[] {
new Sub1ItemProviderAdapterFactory(),
new Sub2ItemProviderAdapterFactory()
};
}
2) modify the two following methods :
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public boolean isFactoryForType(Object type) {
boolean res = supportedTypes.contains(type)
|| super.isFactoryForType(type);
if (res) return true;
// search for AdapterFactory in subpackages
for (AdapterFactory factory : subPackageFactories) {
if (factory.isFactoryForType(type))
return true;
}
}
return false;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public Adapter adapt(Notifier notifier, Object type) {
Adapter res= super.adapt(notifier, this);
if (res==null) {
for (AdapterFactoryImpl factory : subPackageFactories) {
res = factory.adapt(notifier, type);
if (res!=null) return res;
}
}
return res;
}
3) run your diagram editor, you should see the property view for all
your model objects.
Steven
Steven Derrien a écrit :
Hello,
As mentionned in the title, I am having problems with a GMF diagram
editor which is based on a ecore model with subpackages (see attached
file).
Whenever I select in the editor an EditPart corresponding to a EClass of
a subpackage, Its property view is always empty, this does not happen
for EClass that are defined in the main (root) package.
Any idea on how to solve this issue ?
Thanks in advance,
Steven