Home » Modeling » EMF » Custom Property dialog
Custom Property dialog [message #1220432] |
Wed, 11 December 2013 12:30  |
Eclipse User |
|
|
|
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 12:49   |
Eclipse User |
|
|
|
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
|
|
| | | | | | |
Re: Custom Property dialog [message #1222758 is a reply to message #1220997] |
Sat, 21 December 2013 04:25   |
Eclipse User |
|
|
|
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: Tue Jul 08 01:35:54 EDT 2025
Powered by FUDForum. Page generated in 0.04397 seconds
|