Home » Modeling » EMF » Custom Property dialog
Custom Property dialog [message #1220432] |
Wed, 11 December 2013 17:30 |
Phil H Messages: 267 Registered: November 2012 |
Senior Member |
|
|
Hi,
I've created a custom property dialog for one of my properties. Within this dialog, I'm able to add elements, as you can see here:
I've realised this through an AddCommand:
EditingDomain editingDomain = org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(fm);
Command cmdRequiredConstraint = AddCommand.create(editingDomain, fm, PldPackage.Literals.FEATURE_MODEL__INTERNAL_CONSTRAINTS,constraint); editingDomain.getCommandStack().execute(cmdRequiredConstraint);
This works fine so far, but when I'm saving my file, close it and open it again, the properties are removed:
What can be the problem?
nother thing which doesn't work is deleting elements. I tried, accordingly to the AddCommand, remove eleemnts via the RemoveCommand, which doesn't work:
EditingDomain editingDomain = org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(fm);
Command cmdDeleteConstraint = RemoveCommand.create(editingDomain, constraint);
editingDomain.getCommandStack().execute(cmdDeleteConstraint);
I also tried the DeleteCommand, which has the same effect. Why is adding elements working and deleting not?
Cheers,
Phil
|
|
|
Re: Custom Property dialog [message #1220438 is a reply to message #1220432] |
Wed, 11 December 2013 17:49 |
Ed Merks Messages: 33139 Registered: July 2009 |
Senior Member |
|
|
Phil,
Are
On 11/12/2013 6:30 PM, Phil H wrote:
> Hi,
>
> I've created a custom property dialog for one of my properties. Within this dialog, I'm able to add elements, as you can see here:
>
>
>
> I've realised this through an AddCommand:
>
> EditingDomain editingDomain = org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(fm);
> Command cmdRequiredConstraint = AddCommand.create(editingDomain, fm, PldPackage.Literals.FEATURE_MODEL__INTERNAL_CONSTRAINTS,constraint); editingDomain.getCommandStack().execute(cmdRequiredConstraint);
>
> This works fine so far, but when I'm saving my file, close it and open it again, the properties are removed:
>
>
>
> What can be the problem?
Is this a containment reference or a non-containment reference?
>
> nother thing which doesn't work is deleting elements. I tried, accordingly to the AddCommand, remove eleemnts via the RemoveCommand, which doesn't work:
>
>
> EditingDomain editingDomain = org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(fm);
>
> Command cmdDeleteConstraint = RemoveCommand.create(editingDomain, constraint);
> editingDomain.getCommandStack().execute(cmdDeleteConstraint);
>
>
> I also tried the DeleteCommand, which has the same effect. Why is adding elements working and deleting not?
>
> Cheers,
> Phil
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: Custom Property dialog [message #1220445 is a reply to message #1220444] |
Wed, 11 December 2013 19:15 |
Phil H Messages: 267 Registered: November 2012 |
Senior Member |
|
|
Hmm, It's odd for me then that this references are shown in the property descriptor. Shouldn't this be a sign, that this references are correct?
Is this meant by a non-containment reference?:
class FeatureM{
.....
ref VariantConstraint[*] internalConstraints;
}
class VariantConstraint{
...
ref FeatureM featureM;
}
[Updated on: Wed, 11 December 2013 19:17] Report message to a moderator
|
|
| | | |
Re: Custom Property dialog [message #1222758 is a reply to message #1220997] |
Sat, 21 December 2013 09:25 |
Phil H Messages: 267 Registered: November 2012 |
Senior Member |
|
|
Ok I'll try to give you a clearer view about my context. As already mentioned in the first post, I've customized the normal property dialog for one of my elements. To call my custom dialog, I've provided my own implementation of PropertySource:
public class ProductLinePropertySource extends PropertySource {
public ProductLinePropertySource(Object object,
IItemPropertySource itemPropertySource) {
super(object, itemPropertySource);
}
@Override
protected IPropertyDescriptor createPropertyDescriptor(
IItemPropertyDescriptor itemPropertyDescriptor) {
PldPackage pkg = PldPackage.eINSTANCE;
Object obj = itemPropertyDescriptor.getFeature(object);
if (pkg.getFeatureModel_InternalConstraints().equals(obj)) {
return new ConstraintPropertyDescriptor(object, itemPropertyDescriptor);
} else {
// Else, default EMF behavior
return super.createPropertyDescriptor(itemPropertyDescriptor);
}
}
Inside my PropertyDescriptor, I'm calling my custom dialog:
public class ConstraintPropertyDescriptor extends PropertyDescriptor {
public ConstraintPropertyDescriptor(Object object,
IItemPropertyDescriptor itemPropertyDescriptor) {
super(object, itemPropertyDescriptor);
}
@Override
public CellEditor createPropertyEditor(Composite parent) {
return new ExtendedDialogCellEditor(parent, getLabelProvider()) {
@Override
protected Object openDialogBox(Control cellEditorWindow) {
Shell shell = Display.getCurrent().getActiveShell();
if (object instanceof FeatureModel) {
FeatureModel fm = (FeatureModel) object;
ConstraintDialog dialog = new ConstraintDialog(fm, shell);
dialog.open();
}
return null;
}
};
}
}
Whereas my custom dialog allows to add properties to the element, as realizes in the add and delete buttons.
As shown in the the first post, the add command seems to work, while the delete command has no affect.
protected Control createDialogArea(final Composite parent) {
final Composite container = (Composite) super.createDialogArea(parent);
........
btnAddConstraint.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
VariantConstraint constraint = PldFactory.eINSTANCE.createVariantConstraint();
constraint.setConstraintType(ConstraintType.EXCLUDE);
EditingDomain editingDomain = org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(fm);
Command cmdRequiredConstraint = AddCommand.create(editingDomain, fm, PldPackage.Literals.FEATURE_MODEL__INTERNAL_CONSTRAINTS, constraint);
editingDomain.getCommandStack().execute(cmdRequiredConstraint);
}
});
.......
btnDeleteConstraint.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
StructuredSelection constraintSelection = (StructuredSelection) lvConstraints.getSelection();
VariantConstraint constraint = (VariantConstraint) constraintSelection.getFirstElement();
EditingDomain editingDomain = org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(fm);
Command cmdDeleteConstraint = RemoveCommand.create(editingDomain, constraint);
editingDomain.getCommandStack().execute(cmdDeleteConstraint);
}
});
return container;
}
|
|
| |
Goto Forum:
Current Time: Sat Apr 20 14:49:13 GMT 2024
Powered by FUDForum. Page generated in 0.04347 seconds
|