Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » How to append a text node to a EObject
icon5.gif  How to append a text node to a EObject [message #1655899] Sat, 07 March 2015 08:39 Go to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 145
Registered: July 2009
Senior Member
Maybe this is a stupid question. But I can't figure out how to extend the CustomTask Example.

I have a EObject named 'Parameter' form the Example. This Object has two properties 'name' and 'value'. I am able to create such a parameter at runtime

 Parameter param = ModelFactory.eINSTANCE.createParameter();
 param.setName("workflowsummary");
 param.setValue("my data....");


This results in a xml like this:

 <imixs:taskConfig>
          <imixs:parameter xsi:type="imixs:Parameter" name="workflowsummary" value="my data...."/>
</imixs:taskConfig> 


But what I need is to store the value into the parameter tag itself (this is because the data can be a very very long text.
The xml should look like this:

 <imixs:taskConfig>
          <imixs:parameter xsi:type="imixs:Parameter" name="workflowsummary" >my data....
        </imixs:parameter> 
</imixs:taskConfig> 


How can I manage this?
Can anybody please help me here a little bit?

===
Ralph

Re: How to append a text node to a EObject [message #1658305 is a reply to message #1655899] Sun, 08 March 2015 09:17 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 145
Registered: July 2009
Senior Member
I have come a little closer to a solution.
I changed the model definition for the 'Parameter' element in my ecore file like this:

 <eClassifiers xsi:type="ecore:EClass" name="Parameter">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" upperBound="-1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>


Now this results in a XML output in my bpmn file like this:

<bpmn2:extensionElements>
 <imixs:taskConfig>
  <imixs:parameter xsi:type="imixs:Parameter" name="txtMailSubject">
    <value>Hello world</value>
  </imixs:parameter>
  <imixs:parameter xsi:type="imixs:Parameter" name="txtMailBody">
    <value>Some long message...</value>
  </imixs:parameter>
  <imixs:parameter xsi:type="imixs:Parameter" name="txtMailReceifer">
    <value>test@a.com</value>
    <value>test@b.com</value>
  </imixs:parameter>
 </imixs:taskConfig>
</bpmn2:extensionElements>


The values can be taken form the Paramertobject as a EList

	EList<String> valueList = subjectParam.getValue();


But how can I bound now only the first element of the list to a widget.
The normal bindAttribute will not work:
....
	Parameter subjectParam = getProperty("txtMailSubject");
	// this did not work because only the first element of the value list should be bound.....?
	bindAttribute(getAttributesParent(),subjectParam,"value", "Subject");					
...


The reason why I need a list here is that I also want to bind CheckBox Input widgets which will result in a multi-value list. I think this is currently not yet directly supported with a bindAttribute() method?

So at the end I have two problems here:

1. I want to store the content of a input (multiline input) not in an attribute but in a textnode.
2. I want to handle multi-value inputs like a checkbox input


===
Ralph
Re: How to append a text node to a EObject [message #1662254 is a reply to message #1658305] Tue, 10 March 2015 00:39 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hi Ralph,

I am currently updating the customTask example plugin to include an extension element that has a name & value - the value is stored in a CDATA in the element. I believe this is what you were looking for.

It turns out, this is not as easy as it seems Wink I will create a new snapshot build for Luna by tomorrow after I finish testing it. This will be version 1.1.3 (because 1.1.2 is already frozen).

Cheers,
Bob
Re: How to append a text node to a EObject [message #1676104 is a reply to message #1662254] Sun, 15 March 2015 10:25 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 145
Registered: July 2009
Senior Member
Hi Bob,

the CData example works great and I have adapted it for my project.
But I still have a question:

In the CustomPropertyTabs Tutorial you explain that Model changes should only be made in response to a deliberate user action and not in the createBindings method. You example shows how a new MetaData extension Element is added by pressing a Button in the property section. But also in this example you put the code, which modifies the EObject into a TransactionalEditingDomain execute block.

So why is the following code - which did the same - not recommanded? I just want to verify that my Element contains a MetaData extension with the name 'txtSubject'. And it works without any problems.

public class MailPropertySection extends AbstractImixsPropertySection {

	final static EStructuralFeature METADATA_FEATURE = ModelPackage.eINSTANCE.getDocumentRoot_MetaData();
	final static EStructuralFeature METADATA_VALUE = ModelPackage.eINSTANCE.getMetaData_Value();

	@Override
	protected AbstractDetailComposite createSectionRoot() {
		return new MailDetailComposite(this);
	}

	@Override
	public AbstractDetailComposite createSectionRoot(Composite parent, int style) {
		return new MailDetailComposite(parent, style);
	}

	public class MailDetailComposite extends AbstractDetailComposite {
		public MailDetailComposite(AbstractBpmn2PropertySection section) {
			super(section);
		}

		public MailDetailComposite(Composite parent, int style) {
			super(parent, style);
		}

		@Override
		public void createBindings(final EObject be) {
			if (be==null || !(be instanceof IntermediateCatchEvent)) {
				return;
			}
			
			setTitle("Mail Configuration");
			
			 // create a new Property Tab section with a twistie
	        Composite section = createSectionComposite(this, "Mail Body");
	        // get the MetaData object from this BaseElement's extension elements
	        MetaData metaData = (MetaData) findExtensionAttributeValue((BaseElement)be, METADATA_FEATURE,"txtSubject");
	        if (metaData==null) {
	        	// create the new MetaData and insert it into the
                // BaseElement's extension elements container
                // Note that this has to be done inside a transaction
                TransactionalEditingDomain domain = getDiagramEditor().getEditingDomain();
                domain.getCommandStack().execute(new RecordingCommand(domain) {
                    @Override
                    protected void doExecute() {
                    	MetaData metaData = ModelFactory.eINSTANCE.createMetaData();
                        metaData.setValue("Some Subject....");
                        metaData.setName("txtSubject");
                        addExtensionAttributeValue((BaseElement)be, METADATA_FEATURE, metaData);
                        setBusinessObject(be);
                    }
                });
	        } else {
	        	 TextObjectEditor valueEditor = new TextObjectEditor(this, metaData, METADATA_VALUE);
	            // valueEditor.setMultiLine(true);
	            
	             valueEditor.createControl(this, "Value");
	        }
		}
		
		
		/**
		 * Add a new extension element to the given BaseElement.
		 */
		void addExtensionAttributeValue(BaseElement be, EStructuralFeature feature, Object value) {
			ExtensionAttributeValue eav = null;
			if (be.getExtensionValues().size()>0) {
				// reuse the <bpmn2:extensionElements> container if this BaseElement already has one
				eav = be.getExtensionValues().get(0);
			}
			else {
				// otherwise create a new one
				eav = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
				be.getExtensionValues().add(eav);
			}
			eav.getValue().add(feature, value);
		}
		
		/**
		 * Find the first entry in this BaseElement's extension elements container
		 * that matches the given structural feature MetaData and the name.
		 */
		Object findExtensionAttributeValue(BaseElement be, EStructuralFeature feature,String itemName) {
		    for (ExtensionAttributeValue eav : be.getExtensionValues()) {
		        for (FeatureMap.Entry entry : eav.getValue()) {
		            if (entry.getEStructuralFeature() == feature) {		            	
		            	if (entry.getValue() instanceof MetaData) {
		            		MetaData confItem=(MetaData) entry.getValue();
		            		if (confItem.getName().equals(itemName))
		            			return confItem;
		            			//return entry.getValue();		            
		            	}
		            }
		        }
		    }
		    return null;
		}
	}
}


===
Ralph

[Updated on: Sun, 15 March 2015 10:25]

Report message to a moderator

Re: How to append a text node to a EObject [message #1689061 is a reply to message #1676104] Sun, 22 March 2015 15:27 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hey Ralph,

It looks like you're making a model change in createBindings() and this method is called whenever the property tab is displayed, e.g. when you select the Task or whichever object to which the property tab belongs. This is not what I would call a "deliberate user action" - the user would not expect to be making a change to the model simply by looking at it (disregarding the Observer Effect of quantum physics of course Wink )

Cheers,
Bob
Re: How to append a text node to a EObject [message #1690057 is a reply to message #1689061] Tue, 24 March 2015 21:36 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 145
Registered: July 2009
Senior Member
Hi Bob,

yes your are right - this is really strange on the first look.
But in my case the property tabs should more be a kind of 'aspect' to the task. The properties are not forcing required for the engine. The task can contain such information (like in my case a E-Mail configuration) or not. In both cases the model is valid.
Thus, it is indeed that I first must add this properties to the model when the user open this tab or fills out the input widgets.
On the other side it can happen that extensions of my plugin will add other 'optional' property tabs. So for me it is that what I expect. If I open an older model with a newer version of my plugin, the new properties (the new aspect) will be added to the model. So the property tab is the only model element knowing the properties - or the new Aspect of the Task.
I guess that the only 'clean' solution would be to parse the model before I open it. But also in this case I need to change the model when new properties are added in the future.
I think I can (must) live with this "Observer Effect of quantum physics" Wink

Thanks clarifying that issue.
Ralph
Re: How to append a text node to a EObject [message #1690069 is a reply to message #1690057] Tue, 24 March 2015 23:14 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Why not use the InsertionAdapter pattern?
Re: How to append a text node to a EObject [message #1690513 is a reply to message #1690069] Fri, 27 March 2015 17:37 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 145
Registered: July 2009
Senior Member
Hi Bob,

finally I got the trick with the InsertionAdapter.

Now my createBindings method looks like this and works perfect.

@Override
public void createBindings(final EObject be) {
	if (be == null || !(be instanceof IntermediateCatchEvent)) {
		return;
	}
	setTitle("Mail Configuration");
	// create a new Property Tab section with a twistie
	Composite section = createSectionComposite(this, "Mail Body");
	// get the MetaData object from this BaseElement's extension
	// elements
	ConfigItem metaData = (ConfigItem) findExtensionAttributeValue(
			(BaseElement) be, METADATA_FEATURE, "txtSubject");
	if (metaData == null) {
		// create the new MetaData and insert it into the
		// BaseElement's extension elements container
		metaData = ModelFactory.eINSTANCE.createConfigItem();
		metaData.setValue("Some Subject....");
		metaData.setName("txtSubject");
		// addExtensionAttributeValue
		ExtensionAttributeValue eav = null;
		if (((BaseElement) be).getExtensionValues().size() == 0) {
			// otherwise create a new one
			eav = Bpmn2Factory.eINSTANCE
					.createExtensionAttributeValue();
			InsertionAdapter.add(eav, METADATA_FEATURE, metaData);
			InsertionAdapter.add(be, Bpmn2Package.eINSTANCE
					.getBaseElement_ExtensionValues(), eav);
		} else {
			// reuse the <bpmn2:extensionElements> container if this
			// BaseElement already has one
			eav = ((BaseElement) be).getExtensionValues().get(0);
		}
	}
	TextObjectEditor valueEditor = new TextObjectEditor(this, metaData,
			METADATA_VALUE);
	// valueEditor.setMultiLine(true);
	valueEditor.setStyle(SWT.MULTI | SWT.V_SCROLL);
	valueEditor.createControl(this, "Value");
}


Thanks a lot!!

===
Ralph
Re: How to append a text node to a EObject [message #1690669 is a reply to message #1690513] Mon, 30 March 2015 13:32 Go to previous message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Awesome Smile
Previous Topic:Define a customized BPMN modeler palette
Next Topic:No, I haven't been hit by a bus...
Goto Forum:
  


Current Time: Wed Aug 22 01:24:55 GMT 2018

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

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

Back to the top