@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;
}
}
]]>