|
|
|
|
Re: Track change notifications [message #1863971 is a reply to message #1863968] |
Fri, 08 March 2024 12:29 |
Klarise Hund Messages: 24 Registered: October 2022 |
Junior Member |
|
|
By trigger actions I mean, for instance, if a certain attribute is set to a certain value , then, the user will have readonly permissions on the name attribute of the same element ). for instance in the following I have made changes to the BookItemProvider, so that if the year attribute is set to "2007", the name attribute of that particular Book will be readonly. For other Books where the year is != 2007, the name attribute should be able to be edited.
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);
// Dynamically determine if the name property should be read-only
boolean isNameReadOnly = false;
if (object instanceof Book) {
Book book = (Book) object;
if (book.getYear() == 2007) {
isNameReadOnly = true;
}
}
addNamePropertyDescriptor(object, isNameReadOnly);
addYearPropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
// Updated to include dynamic read-only logic
protected void addNamePropertyDescriptor(Object object, boolean isReadOnly) {
itemPropertyDescriptors.add(createItemPropertyDescriptor(
((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(),
getResourceLocator(), getString("_UI_Book_name_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Book_name_feature", "_UI_Book_type"),
LibraryProjectPackage.Literals.BOOK__NAME, true, false, isReadOnly,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
if (notification.getFeatureID(Book.class) == LibraryProjectPackage.BOOK__YEAR) {
// Year has changed, so refresh property descriptors to potentially update read-only status
itemPropertyDescriptors = null;
}
switch (notification.getFeatureID(Book.class)) {
case LibraryProjectPackage.BOOK__NAME:
case LibraryProjectPackage.BOOK__YEAR:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
}
|
|
|
|
Re: Track change notifications [message #1863973 is a reply to message #1863972] |
Fri, 08 March 2024 13:23 |
Klarise Hund Messages: 24 Registered: October 2022 |
Junior Member |
|
|
I made the following changes, and it seems to be working. At least for now :)
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
// Always clear the old descriptors to ensure they are re-evaluated for the current object state
itemPropertyDescriptors = null;
super.getPropertyDescriptors(object);
// Note: We do not need to pass isReadOnly flag here anymore
addNamePropertyDescriptor(object); // Adjust this method to evaluate read-only condition internally
addYearPropertyDescriptor(object);
return itemPropertyDescriptors;
}
// Adjusted to evaluate read-only condition internally
protected void addNamePropertyDescriptor(Object object) {
boolean editName = true;
if (object instanceof Book) {
Book book = (Book) object;
if (book.getYear() == 2007) {
editName = false;
}
}
itemPropertyDescriptors.add(createItemPropertyDescriptor(
((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(),
getResourceLocator(), getString("_UI_Book_name_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Book_name_feature", "_UI_Book_type"),
LibraryProjectPackage.Literals.BOOK__NAME, editName, false, false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}
|
|
|
Powered by
FUDForum. Page generated in 0.04155 seconds