Home » Modeling » EMF » Collecting all objects for treeviewer
Collecting all objects for treeviewer [message #857416] |
Thu, 26 April 2012 14:12 |
El Shorty Messages: 37 Registered: March 2012 |
Member |
|
|
Hey all,
I've got a small question, I have a treeviewer that lists all my groups & persons. I've done this already on 10 different ways but now I found a way that looks decent enough, so I would like to use this. I just got on problem, I don't know how to add a new group to the tree. This is what I do:
TreeViewer treeViewer = new TreeViewer(composite_1, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
[color=orangered]GroupList list = new GroupList();
List<Group> groups = list.getGroups();
GroupCollection allGroups = SmartsignatureFactory.eINSTANCE.createGroupCollection();
allGroups.getContaintsGroups().addAll(groups);[/color]
IObservableList observableList = EMFObservables.observeList(allGroups,
SmartsignaturePackage.Literals.GROUP_COLLECTION__CONTAINTS_GROUPS);
IObservableFactory factory = new IObservableFactory() {
@Override
public IObservable createObservable(Object target) {
if (target instanceof Group)
{
return EMFProperties.list(
SmartsignaturePackage.Literals.GROUP__CONTAINS_PERSONS).observe(target);
} else if (target instanceof IObservable) {
return (IObservable) target;
}
return null;
}
};
// Advisor
TreeStructureAdvisor advisor = new TreeStructureAdvisor() {
@Override
public Boolean hasChildren(Object element) {
if (element instanceof Group) {
return ((Group) element).getContainsPersons().size() != 0;
}
return super.hasChildren(element);
}
};
ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(
factory, advisor);
IObservableMap[] maps = new IObservableMap[3];
maps[0] = EMFProperties.value(
SmartsignaturePackage.Literals.GROUP__NAME).observeDetail(
contentProvider.getKnownElements());
maps[1] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.PERSON__FIRST_NAME))
.observeDetail(contentProvider.getKnownElements());
maps[2] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.PERSON__LAST_NAME))
.observeDetail(contentProvider.getKnownElements());
ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(
maps) {
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Group) {
Group group = (Group) element;
return group.getName();
}
if (element instanceof Person) {
Person person = (Person) element;
return person.getFirstName() + " " + person.getLastName();
}
return super.getColumnText(element, columnIndex);
}
public Image getImage(Object element) {
if (element instanceof Group) {
return ResourceManager.getPluginImage("smartapps.smartsignature.ui.admin", "icons/user-group-icon.png");
}
return ResourceManager.getPluginImage("smartapps.smartsignature.ui.admin", "icons/user-icon.png");
}
};
treeViewer.setContentProvider(contentProvider);
treeViewer.setLabelProvider(labelProvider);
treeViewer.setInput(observableList);
what I want is that instead of creating a list of all the group objects and placing them in a collection object, I'ld like that it does that on it's own.
One option I was thinking about was making it so that whenever a group is added, it also get's added to the groupCollection object, I can do that manually but that just sounds wrong.
Hope you can see what I mean,
any help is much appreciated
[Updated on: Thu, 26 April 2012 14:14] Report message to a moderator
|
|
| |
Re: Collecting all objects for treeviewer [message #865285 is a reply to message #865275] |
Mon, 30 April 2012 10:20 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 30/04/2012 12:14 PM, El Shorty wrote:
> Ok, since I got no answer I'll try again.
> What I want is that whenever a group gets added or deleted, my
> treeviewer that shows the groups and the content from the groups to
> update itself. I'm trying to listen to the resource that contains all
> the groups by using an adapter but I must be something wrong because
> the adapter never gets triggered. Here is the code from the tree I
> have so far:
>
>
> IObservableList observableList = EMFObservables.observeList(allGroups,
>
> SmartsignaturePackage.Literals.GROUP_COLLECTION__CONTAINS_GROUPS);
>
> IObservableFactory factory = new IObservableFactory() {
>
> @Override
> public IObservable createObservable(Object target) {
> if (target instanceof Group)
> {
> return EMFProperties.list(
>
> SmartsignaturePackage.Literals.GROUP__CONTAINS_PERSONS).observe(target);
> } else if (target instanceof IObservable) {
> return (IObservable) target;
> }
> return null;
> }
> };
>
> // Advisor
> TreeStructureAdvisor advisor = new TreeStructureAdvisor() {
> @Override
> public Boolean hasChildren(Object element) {
> if (element instanceof Group) {
> return ((Group)
> element).getContainsPersons().size() != 0;
> }
> return super.hasChildren(element);
> }
> };
> ObservableListTreeContentProvider contentProvider =
> new ObservableListTreeContentProvider(
> factory, advisor);
> IObservableMap[] maps = new IObservableMap[3];
> maps[0] = EMFProperties.value(
>
> SmartsignaturePackage.Literals.GROUP__NAME).observeDetail(
> contentProvider.getKnownElements());
> maps[1] = EMFProperties.value(
> FeaturePath.fromList(
>
> SmartsignaturePackage.Literals.PERSON__FIRST_NAME))
> .observeDetail(contentProvider.getKnownElements());
> maps[2] = EMFProperties.value(
> FeaturePath.fromList(
>
> SmartsignaturePackage.Literals.PERSON__LAST_NAME))
> .observeDetail(contentProvider.getKnownElements());
> ObservableMapLabelProvider labelProvider = new
> ObservableMapLabelProvider(
> maps) {
> public String getColumnText(Object element, int
> columnIndex) {
> if (element instanceof Group) {
> Group group = (Group) element;
> return group.getName();
> }
> if (element instanceof Person) {
> Person person = (Person) element;
> return person.getFirstName() + " " +
> person.getLastName();
> }
>
> return super.getColumnText(element, columnIndex);
> }
>
>
> };
> treeViewer.setContentProvider(contentProvider);
> treeViewer.setLabelProvider(labelProvider);
> treeViewer.setInput(observableList);
>
>
>
> And I try to add an EContentAdapter to my resource like this:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI =
> URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.Groups));
> Resource loadResource = resourceSet.getResource(fileURI, true);
>
> EContentAdapter adapter = new EContentAdapter() {
> public void notifyChanged(Notification notification) {
Did you look at what this method does in the base class?
> treeViewer.refresh();
> }
> };
> loadResource.eAdapters().add(adapter);
>
> But the adapter never gets triggered. The idea of this was that
> whenever the resource changed, the adapter would get triggered and the
> tree would refresh itself.
I would have expected that data binding would take care of the refresh
via the observables.
>
> I hope this makes more sense that my first post. Any idea's anyone?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Collecting all objects for treeviewer [message #865340 is a reply to message #865285] |
Mon, 30 April 2012 10:54 |
El Shorty Messages: 37 Registered: March 2012 |
Member |
|
|
It takes care of the refresh using the observables, whenever I adjust an existing group, the adjustment is added but when I add or delete a group nothing changes.
IObservableList observableList = EMFObservables.observeList(allGroups,
SmartsignaturePackage.Literals.GROUP_COLLECTION__CONTAINS_GROUPS);
I know it is because it obsevers allGroups, problem here is that allGroups is a collection of the already existing groups, but I don't know how to add the new groups to it, that is why I wanted the adapter so that I could add new groups whenever the adapter was triggered.
Perhaps it is possible that instead of using groupList, I could use the resource that contains all the groups.
That would be:
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.Groups));
Resource loadResource = resourceSet.getResource(fileURI, true);
I believe that if I could use loadResource instead of allGroups, my problem would be solved but I have no idea how I could do this, that's why I was trying to check if loadResource changed, because if it did than I could manually add my groups by using the adapter.
I'm hoping I make sense
|
|
|
Re: Collecting all objects for treeviewer [message #865378 is a reply to message #865340] |
Mon, 30 April 2012 11:18 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
I think you'd typically use EMFProperties or EMFEditProperties and use
the resource method to observe the contents of a resource.
On 30/04/2012 12:54 PM, El Shorty wrote:
> It takes care of the refresh using the observables, whenever I adjust
> an existing group, the adjustment is added but when I add or delete a
> group nothing changes.
>
>
> IObservableList observableList = EMFObservables.observeList(allGroups,
>
> SmartsignaturePackage.Literals.GROUP_COLLECTION__CONTAINS_GROUPS);
>
>
> I know it is because it obsevers allGroups, problem here is that
> allGroups is a collection of the already existing groups, but I don't
> know how to add the new groups to it, that is why I wanted the adapter
> so that I could add new groups whenever the adapter was triggered.
> Perhaps it is possible that instead of using groupList, I could use
> the resource that contains all the groups. That would be:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI =
> URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.Groups));
> Resource loadResource = resourceSet.getResource(fileURI, true);
>
>
> I believe that if I could use loadResource instead of allGroups, my
> problem would be solved but I have no idea how I could do this, that's
> why I was trying to check if loadResource changed, because if it did
> than I could manually add my groups by using the adapter.
>
> I'm hoping I make sense
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: Collecting all objects for treeviewer [message #865632 is a reply to message #865556] |
Mon, 30 April 2012 13:51 |
El Shorty Messages: 37 Registered: March 2012 |
Member |
|
|
I'll post the full code I'm using for the treeviewer, just in case anyone sees what I'm overlooking...
public class GroupView extends ViewPart implements ISelectionListener {
private TreeViewer treeViewer;
public GroupView() {
super();
}
@Override
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
Composite composite_1 = new Composite(composite, SWT.NONE);
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
composite_1.setLayout(new TreeColumnLayout());
treeViewer = new TreeViewer(composite_1, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.Groups));
Resource loadResource = resourceSet.getResource(fileURI, true);
IObservableList observableList = EMFProperties.resource().observe(loadResource);
IObservableFactory factory = new IObservableFactory() {
@Override
public IObservable createObservable(Object target) {
if (target instanceof Group)
{
return EMFProperties.list(
SmartsignaturePackage.Literals.GROUP__CONTAINS_PERSONS).observe(target);
} else if (target instanceof IObservable) {
return (IObservable) target;
}
return null;
}
};
// Advisor
TreeStructureAdvisor advisor = new TreeStructureAdvisor() {
@Override
public Boolean hasChildren(Object element) {
if (element instanceof Group) {
return ((Group) element).getContainsPersons().size() != 0;
}
return super.hasChildren(element);
}
};
ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(
factory, advisor);
IObservableMap[] maps = new IObservableMap[3];
maps[0] = EMFProperties.value(
SmartsignaturePackage.Literals.GROUP__NAME).observeDetail(
contentProvider.getKnownElements());
maps[1] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.PERSON__FIRST_NAME))
.observeDetail(contentProvider.getKnownElements());
maps[2] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.PERSON__LAST_NAME))
.observeDetail(contentProvider.getKnownElements());
ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(
maps) {
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Group) {
Group group = (Group) element;
return group.getName();
}
if (element instanceof Person) {
Person person = (Person) element;
return person.getFirstName() + " " + person.getLastName();
}
return super.getColumnText(element, columnIndex);
}
public Image getImage(Object element) {
if (element instanceof Group) {
return ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview", "icons/user-group-icon.png");
}
return ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview", "icons/user-icon.png");
}
};
treeViewer.setContentProvider(contentProvider);
treeViewer.setLabelProvider(labelProvider);
treeViewer.setInput(observableList);
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// TODO Auto-generated method stub
}
}
|
|
|
Re: Collecting all objects for treeviewer [message #868533 is a reply to message #865632] |
Wed, 02 May 2012 06:57 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
So where is the code that adds/removes a group? You should try to come
up with code we can locally to reproduce your problem.
We are using EMF-Databinding in many of our projects and if this would
be broken our software would be too. So there's some special about your
code which I can't see without running it.
Tom
Am 30.04.12 15:52, schrieb El Shorty:
> I'll post the full code I'm using for the treeviewer, just in case
> anyone sees what I'm overlooking...
>
>
> public class GroupView extends ViewPart implements
> ISelectionListener {
>
> private TreeViewer treeViewer;
>
> public GroupView() {
> super();
> }
>
> @Override
> public void createPartControl(Composite parent) {
>
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new GridLayout(1, false));
>
> Composite composite_1 = new Composite(composite, SWT.NONE);
> composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> true, 1, 1));
> composite_1.setLayout(new TreeColumnLayout());
>
> treeViewer = new TreeViewer(composite_1, SWT.BORDER);
> Tree tree = treeViewer.getTree();
> tree.setHeaderVisible(true);
> tree.setLinesVisible(true);
>
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI =
> URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.Groups));
> Resource loadResource = resourceSet.getResource(fileURI, true);
>
> IObservableList observableList =
> EMFProperties.resource().observe(loadResource);
> IObservableFactory factory = new
> IObservableFactory() {
>
> @Override
> public IObservable createObservable(Object target) {
> if (target instanceof Group)
> {
> return EMFProperties.list(
>
> SmartsignaturePackage.Literals.GROUP__CONTAINS_PERSONS).observe(target);
>
> } else if (target instanceof IObservable) {
> return (IObservable) target;
> }
> return null;
> }
> };
>
> // Advisor
> TreeStructureAdvisor advisor = new TreeStructureAdvisor() {
> @Override
> public Boolean hasChildren(Object element) {
> if (element instanceof Group) {
> return ((Group) element).getContainsPersons().size()
> != 0;
> }
> return super.hasChildren(element);
> }
> };
> ObservableListTreeContentProvider contentProvider = new
> ObservableListTreeContentProvider(
> factory, advisor);
> IObservableMap[] maps = new IObservableMap[3];
> maps[0] = EMFProperties.value(
> SmartsignaturePackage.Literals.GROUP__NAME).observeDetail(
> contentProvider.getKnownElements());
> maps[1] = EMFProperties.value(
> FeaturePath.fromList(
> SmartsignaturePackage.Literals.PERSON__FIRST_NAME))
> .observeDetail(contentProvider.getKnownElements());
> maps[2] = EMFProperties.value(
> FeaturePath.fromList(
> SmartsignaturePackage.Literals.PERSON__LAST_NAME))
> .observeDetail(contentProvider.getKnownElements());
> ObservableMapLabelProvider labelProvider = new
> ObservableMapLabelProvider(
> maps) {
> public String getColumnText(Object element, int
> columnIndex) {
> if (element instanceof Group) {
> Group group = (Group) element;
> return group.getName();
> }
> if (element instanceof Person) {
> Person person = (Person) element;
> return person.getFirstName() + " " +
> person.getLastName();
> }
>
> return super.getColumnText(element, columnIndex);
> }
>
> public Image getImage(Object element) {
> if (element instanceof Group) {
> return
> ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview",
> "icons/user-group-icon.png");
> }
> return
> ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview",
> "icons/user-icon.png");
> }
>
> };
> treeViewer.setContentProvider(contentProvider);
> treeViewer.setLabelProvider(labelProvider);
> treeViewer.setInput(observableList);
>
>
> }
>
> @Override
> public void setFocus() {
> // TODO Auto-generated method stub
>
> }
>
> @Override
> public void selectionChanged(IWorkbenchPart part, ISelection
> selection) {
> // TODO Auto-generated method stub
>
> }
>
>
> }
>
>
>
|
|
| | | |
Re: Collecting all objects for treeviewer [message #868592 is a reply to message #868579] |
Wed, 02 May 2012 09:10 |
El Shorty Messages: 37 Registered: March 2012 |
Member |
|
|
Yeah that's what I tought, so now I've made a parent object called GroupCollection, this should contain all the existing groups, whenever I create a new group I add it to the groupCollection object but again nothing changes. I'm guessing I need to adjust my code some more but don't know where anymore, here is what I have now:
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
Composite composite_1 = new Composite(composite, SWT.NONE);
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
composite_1.setLayout(new TreeColumnLayout());
treeViewer = new TreeViewer(composite_1, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.GroupCollections));
loadResource = resourceSet.getResource(fileURI, true);
observableList = EMFProperties.resource().observe(loadResource);
IObservableFactory factory = new IObservableFactory() {
@Override
public IObservable createObservable(Object target) {
if (target instanceof GroupCollection)
{
return EMFProperties.list(
SmartsignaturePackage.Literals.GROUP_COLLECTION__CONTAINS_GROUPS).observe(target);
}
else if (target instanceof Group)
{
return EMFProperties.list(
SmartsignaturePackage.Literals.GROUP__CONTAINS_PERSONS).observe(target);
} else if (target instanceof IObservable) {
return (IObservable) target;
}
return null;
}
};
// Advisor
TreeStructureAdvisor advisor = new TreeStructureAdvisor() {
@Override
public Boolean hasChildren(Object element) {
if (element instanceof GroupCollection) {
return ((GroupCollection) element).getContainsGroups().size() != 0;
}
else if (element instanceof Group) {
return ((Group) element).getContainsPersons().size() != 0;
}
return super.hasChildren(element);
}
};
ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(
factory, advisor);
IObservableMap[] maps = new IObservableMap[4];
maps[0] = EMFProperties.value(
SmartsignaturePackage.Literals.GROUP_COLLECTION__NAME).observeDetail(
contentProvider.getKnownElements());
maps[1] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.GROUP__NAME)).observeDetail(
contentProvider.getKnownElements());
maps[2] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.PERSON__FIRST_NAME))
.observeDetail(contentProvider.getKnownElements());
maps[3] = EMFProperties.value(
FeaturePath.fromList(
SmartsignaturePackage.Literals.PERSON__LAST_NAME))
.observeDetail(contentProvider.getKnownElements());
ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(
maps) {
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Group) {
Group group = (Group) element;
return group.getName();
}
if (element instanceof Person) {
Person person = (Person) element;
return person.getFirstName() + " " + person.getLastName();
}
return super.getColumnText(element, columnIndex);
}
public Image getImage(Object element) {
if (element instanceof Group) {
return ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview", "icons/user-group-icon.png");
}
return ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview", "icons/user-icon.png");
}
};
treeViewer.setContentProvider(contentProvider);
treeViewer.setLabelProvider(labelProvider);
treeViewer.setInput(observableList);
That's to build my tree. If I'm correct it should be observing my groupCollection, but apparantly I'm wrong because when I add a new group in my wizard like this:
SaveMethod save = new SaveMethod();
save.save(group);
openEditor();
addToGroupCollection();
try {
groupCollection.eResource().save(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
public void addToGroupCollection() {
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.GroupCollections));
Resource loadResource = resourceSet.getResource(fileURI, true);
List<EObject> collection = loadResource.getContents();
groupCollection = (GroupCollection) collection.toArray()[0];
groupCollection.getContainsGroups().add(group);
}
I'm sorry for all the questions, I'm really trying to understand this but I keep doing something wrong.. I've only been using EMF & RCP for 2 months, and there is alot to learn & understand. I love it but it's a challenge lolz..
|
|
|
Re: Collecting all objects for treeviewer [message #868631 is a reply to message #868592] |
Wed, 02 May 2012 10:11 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
EMF-Databinding is listening to the in memory model - your code creates
a new resource instance and saves it to the file system. Why are you not
simply attaching the new object to the existing resource instead of
creating a new one all the time?
Did you take a look at the EMF-Databinding example it our source repo it
shows you have to add/remove objects. BTW your new code with the new
root-element requires you to change the observable creation to observe
the list-feature of GroupCollection.
Tom
Am 02.05.12 11:10, schrieb El Shorty:
> Yeah that's what I tought, so now I've made a parent object called
> GroupCollection, this should contain all the existing groups, whenever I
> create a new group I add it to the groupCollection object but again
> nothing changes. I'm guessing I need to adjust my code some more but
> don't know where anymore, here is what I have now:
>
>
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new GridLayout(1, false));
>
> Composite composite_1 = new Composite(composite, SWT.NONE);
> composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> true, 1, 1));
> composite_1.setLayout(new TreeColumnLayout());
>
> treeViewer = new TreeViewer(composite_1, SWT.BORDER);
> Tree tree = treeViewer.getTree();
> tree.setHeaderVisible(true);
> tree.setLinesVisible(true);
>
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI =
> URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.GroupCollections));
>
> loadResource = resourceSet.getResource(fileURI, true);
>
> observableList = EMFProperties.resource().observe(loadResource);
>
> IObservableFactory factory = new IObservableFactory() {
>
> @Override
> public IObservable createObservable(Object target) {
> if (target instanceof GroupCollection)
> {
> return EMFProperties.list(
>
> SmartsignaturePackage.Literals.GROUP_COLLECTION__CONTAINS_GROUPS).observe(target);
>
> }
> else if (target instanceof Group)
> {
> return EMFProperties.list(
>
> SmartsignaturePackage.Literals.GROUP__CONTAINS_PERSONS).observe(target);
>
> } else if (target instanceof IObservable) {
> return (IObservable) target;
> }
> return null;
> }
> };
>
> // Advisor
> TreeStructureAdvisor advisor = new TreeStructureAdvisor() {
> @Override
> public Boolean hasChildren(Object element) {
> if (element instanceof GroupCollection) {
> return ((GroupCollection)
> element).getContainsGroups().size() != 0;
> }
>
> else if (element instanceof Group) {
> return ((Group) element).getContainsPersons().size()
> != 0;
> }
> return super.hasChildren(element);
> }
> };
> ObservableListTreeContentProvider contentProvider = new
> ObservableListTreeContentProvider(
> factory, advisor);
> IObservableMap[] maps = new IObservableMap[4];
> maps[0] = EMFProperties.value(
>
> SmartsignaturePackage.Literals.GROUP_COLLECTION__NAME).observeDetail(
> contentProvider.getKnownElements());
>
> maps[1] = EMFProperties.value(
> FeaturePath.fromList(
>
> SmartsignaturePackage.Literals.GROUP__NAME)).observeDetail(
> contentProvider.getKnownElements());
> maps[2] = EMFProperties.value(
> FeaturePath.fromList(
> SmartsignaturePackage.Literals.PERSON__FIRST_NAME))
> .observeDetail(contentProvider.getKnownElements());
> maps[3] = EMFProperties.value(
> FeaturePath.fromList(
> SmartsignaturePackage.Literals.PERSON__LAST_NAME))
> .observeDetail(contentProvider.getKnownElements());
> ObservableMapLabelProvider labelProvider = new
> ObservableMapLabelProvider(
> maps) {
> public String getColumnText(Object element, int
> columnIndex) {
> if (element instanceof Group) {
> Group group = (Group) element;
> return group.getName();
> }
> if (element instanceof Person) {
> Person person = (Person) element;
> return person.getFirstName() + " " +
> person.getLastName();
> }
>
> return super.getColumnText(element, columnIndex);
> }
>
> public Image getImage(Object element) {
> if (element instanceof Group) {
> return
> ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview",
> "icons/user-group-icon.png");
> }
> return
> ResourceManager.getPluginImage("smartapps.smartsignature.ui.groupoverview",
> "icons/user-icon.png");
> }
>
> };
> treeViewer.setContentProvider(contentProvider);
> treeViewer.setLabelProvider(labelProvider);
> treeViewer.setInput(observableList);
>
>
>
> That's to build my tree. If I'm correct it should be observing my
> groupCollection, but apparantly I'm wrong because when I add a new group
> in my wizard like this:
>
>
> SaveMethod save = new SaveMethod();
> save.save(group);
> openEditor();
> addToGroupCollection();
> try {
> groupCollection.eResource().save(null);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> return true;
>
> public void addToGroupCollection() {
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI =
> URI.createFileURI(SmartSignResourceUtil.getPath(DataPart.GroupCollections));
>
> Resource loadResource = resourceSet.getResource(fileURI, true);
> List<EObject> collection = loadResource.getContents();
> groupCollection = (GroupCollection) collection.toArray()[0];
> groupCollection.getContainsGroups().add(group);
> }
>
>
>
> I'm sorry for all the questions, I'm really trying to understand this
> but I keep doing something wrong.. I've only been using EMF & RCP for 2
> months, and there is alot to learn & understand. I love it but it's a
> challenge lolz..
|
|
| | | | |
Goto Forum:
Current Time: Fri Apr 19 19:46:38 GMT 2024
Powered by FUDForum. Page generated in 0.06104 seconds
|