Properties and Listeners [message #565867] |
Tue, 31 August 2010 18:32 |
Daniele Messages: 45 Registered: August 2010 |
Member |
|
|
Hi guys,
May I ask your help to understand if I am properly implementing the listeners for two fields in the property section?
My questions are:
Q1: is it correct to have a different listener for each field/attribute?
Q2: if I have another businessObject, namely "IntentionSpec", which:
- is a specialization of the businessObject "Intention"
- has the two attributes inherited from "Intention" plus another attribute called "newAttribute"
and I want that in the property section when:
i) an "Intention" diagram element is selected --> two attributes are visualized in the panel and if I edit them the "Intention" business object is changed (similar to the actual code)
ii) an "IntentsionSpec" is selected ---> three attributes are visualized in the panel and if I edit them the "IntentionSpec" business object is changed.
Do you have some suggestions how to do that?
For example, should I put everything it the same:
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage)
and add some lines such as:
Object bo= Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);
if (bo == Intention) then
<actual code>
else
<code to visualize the previous two fields + the newAttribute, and in this case I use the same listeners plus a new one>
Is this correct?
Thank you very much for any help or suggestions :)
---------------
...
public class IntentionSection extends GFPropertySection implements ITabbedPropertyConstants {
private Text nameText;
private Text descriptionText;
private ModifyListener listenerIntentionName = new ModifyListener(){
public void modifyText (ModifyEvent arg0){
PictogramElement pe = getSelectedPictogramElement();
Intention bimElement = (Intention) Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);
bimElement.setName(nameText.getText());
bimElement.setDescription(descriptionText.getText());
System.out.print("\Name setted: "+bimElement.getName());
}
};
private ModifyListener listenerIntentionDescription = new ModifyListener(){
public void modifyText (ModifyEvent arg0){
PictogramElement pe = getSelectedPictogramElement();
Intention bimElement = (Intention) Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);
bimElement.setDescription(descriptionText.getText());
System.out.print("\nDescription setted: "+bimElement.getDescription());
}
};
@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
Composite composite = factory.createFlatFormComposite(parent);
FormData data;
// nameText
nameText = factory.createText(composite, ""); //$NON-NLS-1$
data = new FormData();
//data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
data.left = new FormAttachment(0, 100);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(0, VSPACE);
nameText.setLayoutData(data);
//Daniele: I am adding the listener here
nameText.addModifyListener(listenerIntentionName);
CLabel valueLabel = factory.createCLabel(composite, "Name:"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(nameText, -HSPACE);
data.top = new FormAttachment(nameText, 0, SWT.CENTER);
valueLabel.setLayoutData(data);
// descriptionText
descriptionText = factory.createText(composite, "", SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 100);
data.right = new FormAttachment(100, 0);
//TODO: try to modify the layout for property
data.top = new FormAttachment(nameText, VSPACE);
descriptionText.setLayoutData(data);
descriptionText.addModifyListener(listenerIntentionDescripti on);
CLabel valueLabelDescription = factory.createCLabel(composite, "Description:"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
//-HSPACE
data.right = new FormAttachment(descriptionText, -HSPACE);
data.top = new FormAttachment(descriptionText, 0, SWT.CENTER);
valueLabelDescription.setLayoutData(data);
}
@Override
public void refresh() {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);
// the filter assured, that it is a Intention
if (bo == null)
return;
// Remove listener
nameText.removeModifyListener(listenerIntentionName);
// Modify values of the properties
String name = ((Intention) bo).getName();
System.out.print("\nSet Name property: "+name);
nameText.setText(name == null ? "" : name); //$NON-NLS-1$
// (RE)Add listener
nameText.addModifyListener(listenerIntentionName);
// Remove listener
nameText.removeModifyListener(listenerIntentionName);
descriptionText.removeModifyListener(listenerIntentionDescri ption);
String description = ((Intention) bo).getDescription();
System.out.print("\nSet Description property: "+description);
descriptionText.setText(description == null ? "" : description); //$NON-NLS-1$
// (RE)Add listener
descriptionText.addModifyListener(listenerIntentionName);
}
}
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02587 seconds