Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Data Binding] Generic formatted string ComputedValue
[Data Binding] Generic formatted string ComputedValue [message #331861] Thu, 25 September 2008 14:38
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

I've written the following ComputedValue that is intended to be a
generic way to format an arbitrary number of IObservableVaulues
according to a pattern.
I have two questions about this:

A) Does this seem generically useful enough to submit for inclusion in
org.eclipse.core.databinding?

B) Any ideas what to do to gracefully handle null values from the
observables? As the code is now, it just inserts the String "null" but
that is not really acceptable IMO.

Eric



public class FormattedStringObservableValue extends ComputedValue {

private MessageFormat pattern;
private IObservableValue[] observables;


public FormattedStringObservableValue(String formatPattern,
IObservableValue... observables) {
setFormatPattern(formatPattern);
setObservables(observables);
}

public FormattedStringObservableValue(MessageFormat formatPattern,
IObservableValue... observables) {
setFormatPattern(formatPattern);
setObservables(observables);
}

public void setObservables(IObservableValue... observables) {
this.observables = observables;
}

public void setFormatPattern(String formatPattern) {
setFormatPattern(new MessageFormat(formatPattern));
}

public void setFormatPattern(MessageFormat formatPattern) {
this.pattern = formatPattern;
}

@Override
protected Object calculate() {
Object[] values = new Object[observables.length];

for (int i = 0; i < observables.length; i++) {
values[i] = observables[i].getValue();
}

return pattern.format(values);
}

}
Previous Topic:Re: Eclipse on Solaris 10
Next Topic:Re: In 3.4 SDK config.ini: what do these org.eclipse.* lines do?
Goto Forum:
  


Current Time: Mon Dec 30 17:40:37 GMT 2024

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

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

Back to the top