Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Accessing domain objects through property section
Accessing domain objects through property section [message #1692149] Tue, 14 April 2015 01:13 Go to next message
Joao Faccin is currently offline Joao FaccinFriend
Messages: 2
Registered: April 2015
Junior Member
Hello everyone,

I'm working on a property section that extends from GFPropertySection. In this property section I have a CCombo, which I want to populate with specific data from a set of instantiated objects in my domain when I select an element of another specific class.

So, I'm running this code in my property section to get this set of instantiated objects:

ArrayList<String> fooClassElements = new ArrayList<String>();
EList<EObject> contents = getDiagram().eResource().getContents();
		for (EObject eObject : contents) {
			if (eObject instanceof FooClass) {
				fooClassElements.add(((FooClass) eObject).getName());
			}
		}


The problem is that I'm getting a NullPointerException from the GFPropertySection#getDiagram() method. Stacktrace shows that the problem arises when AbstractPropertySection#getPart() is called, returning a null value when it must return a valid IWorkbenchPart.

I would like to know if I'm missing something or if there is a better way to access domain instances through a property section.

Thanks in advance!

EDIT: I was mistaken about the scope to use the GFPropertySection#getDiagram() method. I solved the problem moving this code snippet to its correct place.

[Updated on: Tue, 14 April 2015 16:21]

Report message to a moderator

Re: Accessing domain objects through property section [message #1692699 is a reply to message #1692149] Fri, 17 April 2015 11:45 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1894
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Joao,

not sure what goes on here, but have you seen the Tutorial way to do this?
It retrieves the selected object from the editor and works on that. See
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fresources%2Fdocu%2Fgfw%2Fproperty-sheet.htm&cp=27_1_5

Michael
Re: Accessing domain objects through property section [message #1692942 is a reply to message #1692699] Mon, 20 April 2015 18:14 Go to previous messageGo to next message
Joao Faccin is currently offline Joao FaccinFriend
Messages: 2
Registered: April 2015
Junior Member
Hi Michael,

Thanks for your reply.

I had misunderstood the life-cycle of a section, so I was trying to call a method in wrong place. It's fixed and working now. =]

However, I'm facing another problem. I have another PropertySection similar to the previous one containing some textfields to fill and some CCombo.
I'm adding a SelectionListener() for each CCombo for monitoring selection changes and setting this selected values as attribute values for instantiated objects from my domain.
Everything works fine if I have several textfields and one CCombo, but if I add more than one CCombo to the PropertySection when selecting a value on it I got an IllegalStateException saying that a "Transaction is already closing".

For each SelectionListener() I have a code similar to the following:

myCombo.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent arg0) {

				String value = myCombo.getText();
				if (value == null) {
					value = "";//$NON-NLS-1$
				}
				PictogramElement pe = getSelectedPictogramElement();
				if (pe != null) {
					Object bo = Graphiti.getLinkService()
							.getBusinessObjectForLinkedPictogramElement(pe);
					if (bo == null)
						return;
					String myObjectName = "";
					if (((Metadata) bo).getMyObject() != null) {
						myObjectName = ((Metadata) bo)
								.getMyObject().getName();
					}
					if (value.equals(myObjectName))
						return;
				}

				MyObject myObject = null;
				for (MyObject eObject : MyObjects.VALUES) {
					if (eObject.getName().equals(value)) {
						myObject = eObject;
					}
				}

				final MyObject typedValue = myObject;

				IFeature feature = new AbstractFeature(getDiagramTypeProvider()
						.getFeatureProvider()) {

					@Override
					public void execute(IContext context) {
						PictogramElement pe = getSelectedPictogramElement();
						if (pe != null) {
							Object bo = Graphiti
									.getLinkService()
								.getBusinessObjectForLinkedPictogramElement(
											pe);
							if (bo == null)
								return;
							Metadata metadata = (Metadata) bo;
							metadata.setMyObject(typedValue);
						}
					}

					@Override
					public boolean canExecute(IContext context) {
						return true;
					}
				};
				CustomContext context = new CustomContext();
				execute(feature, context);

			}

			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) {
				// TODO Auto-generated method stub
			}
		});


Following the stacktrace, my problem relates to the GFProperySection#execution() method. My expertise about the Command Stack isn't so large yet, so someone have a hint about what I'm doing wrong?

Thanks in advance!
Re: Accessing domain objects through property section [message #1693480 is a reply to message #1692942] Fri, 24 April 2015 12:56 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1894
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Joao,

sorry for the late reply, but I did only that now...

Can you provide the stacktrace and the exct error tex`?

Michael
Previous Topic:Weird code in FeatureExecutionHandler
Next Topic:Single-Click-Feature
Goto Forum:
  


Current Time: Thu Jul 19 15:22:20 GMT 2018

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

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

Back to the top