|
|
Re: How to append a text node to a EObject [message #1662254 is a reply to message #1658305] |
Tue, 10 March 2015 00:39 |
|
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 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 |
Ralph Soika Messages: 193 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 |
|
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 )
Cheers,
Bob
|
|
|
|
|
Re: How to append a text node to a EObject [message #1690513 is a reply to message #1690069] |
Fri, 27 March 2015 17:37 |
Ralph Soika Messages: 193 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04678 seconds