Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » static PropertyDescriptor Validator-problems
static PropertyDescriptor Validator-problems [message #232695] Thu, 05 April 2007 10:15
Eclipse UserFriend
Originally posted by: unidad.gmx.net

Hi NG!

I'm building a little GEF-app and use a code similar to the Shapes-Example.

In a Shapes-Example-GEF-model-element there are properties that can be
displayed in the standard-RCP-properties-view, if the model-element is
selected in the editor. Now there is one big problem I can't solve:

The properties of one model-element displayed in properties-view are
described via an static array of IPropertyDescriptor in the
model-element. (I attached the Shapes-example-code of this passage at
the bottom.)

Further every static IPropertyDescriptor gets one Validator that checks
for example, if an input in the properties-view is a number.

Now I want a check, that considers context-information in the check.
For example I want to check whether X (Property XPOS_PROP) of this
model-element is smaller than Y (Property YPOS_PROP) of this
model-element. For this static Validators don't do it.
In the validator I need information about the selected model-element here.

First solution coming to my mind:
Make the array of IPropertyDescriptor non static and so every
model-element has its own IPropertyDescriptor-objects and
also its own Validator-objects.

But this doesn't work because I use object-serializing to save my
editor-input. And I may not serialize the class
org.eclipse.ui.views.properties.TextPropertyDescriptor

Any other idea how I could perform context-sensitive checks
on a PropertyDescriptor?

Best regards, Ralf


/*
* Initializes the property descriptors array.
* @see #getPropertyDescriptors()
* @see #getPropertyValue(Object)
* @see #setPropertyValue(Object, Object)
*/
static {
descriptors = new IPropertyDescriptor[] {
new TextPropertyDescriptor(XPOS_PROP, "X"),
new TextPropertyDescriptor(YPOS_PROP, "Y"),
new TextPropertyDescriptor(WIDTH_PROP, "Width"),
new TextPropertyDescriptor(HEIGHT_PROP, "Height"),
};
// use a custom cell editor validator for all four array entries
for (int i = 0; i < descriptors.length; i++) {
((PropertyDescriptor) descriptors[i]).setValidator(new
ICellEditorValidator() {
public String isValid(Object value) {
int intValue = -1;
try {
intValue = Integer.parseInt((String) value);
} catch (NumberFormatException exc) {
return "Not a number";
}
return (intValue >= 0) ? null : "Value must be >= 0";
}
});
}
} // static
Previous Topic:How to make a multipageGraphical editor ?
Next Topic:Sashform with toggle-like child visibility
Goto Forum:
  


Current Time: Fri Apr 26 08:38:45 GMT 2024

Powered by FUDForum. Page generated in 0.02657 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top