V.E not writing the code returned by property editor --urgent :please help its [message #125378] |
Tue, 30 May 2006 01:51  |
Eclipse User |
|
|
|
Originally posted by: rashmi_h_r.rediffmail.com
Hi All,
I am facing a problem with the custom property editor that, I have
written for my custom widgets.
The type of the property that I am trying to edit is a double dimension
String array. All the other property editors which are used to edit a
simple string/list are working fine. The getJavaInitialization ()' method
is called for them.
Only in the property editor with the complex data type (Double dimension
String array) the getJavaInitialization () method is not called.
getAsText ()' method is called directly and anything returned from that
method is not reflected (written) on to the code in the Editor window.
The return string from the getAsText ()' Method is of the form as given
below
return
"new String [][]{{\"ssss\",\"ssss\"}}";
The string returned from the getAsText ()'method for the property is
visible correctly as the cell value in the Properties View, but the
property is not set with that value. When I press <-|Enter key on the
cell value, I get a error message saying
IWVA0086E Error: "new String [][]{{\"ssss\",\"ssss\"}}";
Note: When I explicitly invoke the 'setValue()' method from getAsText()
method of the property editor class with a dummy value, the string is
written to the code in the editor window. But, explicit invocation of the
setValue ()' method is not advised in the API.
My custom property editor implementation is working fine in another IDE.
I have also tried clearing all the bean info cache (from
...metadata\.plugins\org.eclipse.jem.beaninfo and
...metadata\.plugins\org.eclipse.core.resources\.projects\<yourproject >\org.eclipse.jem.beaninfo).
But it is still not working.
Please please help It's very urgent:((((((((((
Thank you in advance.
Rashm H.R
Please find the code sampl below.
package mypackage1;
import java.beans.PropertyEditorSupport;
public class ContentTextEditor extends PropertyEditorSupport
{
/**
* Constructor for the ContentTextEditor object
*/
public ContentTextEditor()
{
}
public String getAsText() {
Object obj = this.getValue();
if ( obj instanceof String[])
{
return "new String[]{\"aaaa\",\"bbbb\",\"cccc\"}";
}
return ("" + obj);
}
public void setAsText(String text) throws
java.lang.IllegalArgumentException {
if (this.getValue() instanceof String) {
setValue(text);
return;
}
throw new java.lang.IllegalArgumentException(text);
}
public String getJavaInitializationString()
{
return "\""+getAsText()+"\"";
}
}
|
|
|
|
|
|
Re: V.E not writing the code returned by property editor --urgent :please help its [message #126189 is a reply to message #126176] |
Wed, 14 June 2006 16:31  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Here is an editor that works correctly for String[][]:
package t;
import java.beans.PropertyEditorSupport;
import java.util.ArrayList;
import java.util.List;
public class ContentTextEditor extends PropertyEditorSupport
{
public String getJavaInitializationString() {
Object value = getValue();
if (value == null)
return "null";
else {
StringBuffer b = new StringBuffer("new String[][] {");
String[][] sv = (String[][]) value;
for (int i = 0; i < sv.length; i++) {
if (i > 0)
b.append(',');
b.append('{');
String[] ssv = sv[i];
for (int j = 0; j < ssv.length; j++) {
if (j>0)
b.append(',');
b.append('"');
b.append(ssv[j]);
b.append('"');
}
b.append('}');
}
b.append('}');
return b.toString();
}
}
public String getAsText() {
Object value = getValue();
if (value == null)
return "null";
else if (value instanceof String[][]) {
StringBuffer sb = new StringBuffer();
String[][] v = (String[][]) value;
for (int i = 0; i < v.length; i++) {
String[] vv = v[i];
if (i>0)
sb.append('/');
for (int j = 0; j < vv.length; j++) {
if (j>0)
sb.append(',');
sb.append(vv[j]);
}
}
return sb.toString();
} else
return "???";
}
public void setAsText(String text) throws IllegalArgumentException {
List vl = new ArrayList();
int i = text.indexOf('/');
int b = 0;
while (i >= 0) {
vl.add(getSv(text.substring(b, i)));
b = i+1;
i = text.indexOf('/', b);
}
if (b<text.length())
vl.add(getSv(text.substring(b)));
setValue((String[][]) vl.toArray(new String[vl.size()][]));
}
private String[] getSv(String s) {
List vl = new ArrayList();
int i = s.indexOf(',');
int b = 0;
while (i >= 0) {
vl.add(s.substring(b, i));
b = i+1;
i = s.indexOf(',', b);
}
if (b<s.length())
vl.add(s.substring(b));
return (String[]) vl.toArray(new String[vl.size()]);
}
}
--
Thanks,
Rich Kulp
|
|
|
|
|
Re: V.E not writing the code returned by property editor --urgent :please help its [message #613345 is a reply to message #125378] |
Wed, 14 June 2006 16:08  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
I'm missing something because this editor sample given here can't work.
This editor only works with "String" values, but your are trying to
return a "String[]".
This won't work because the this.value will be set to an "String[][]"
instance. So the setAsText will fail because the value is not an
instanceof String.
>
> package mypackage1;
> import java.beans.PropertyEditorSupport;
> public class ContentTextEditor extends PropertyEditorSupport
> {
> /**
> * Constructor for the ContentTextEditor object
> */
> public ContentTextEditor()
> {
> }
> public String getAsText() {
> Object obj = this.getValue();
> if ( obj instanceof String[]) {
> return "new String[]{\"aaaa\",\"bbbb\",\"cccc\"}";
> }
> return ("" + obj);
> }
> public void setAsText(String text) throws
> java.lang.IllegalArgumentException {
> if (this.getValue() instanceof String) {
> setValue(text);
> return;
> }
> throw new java.lang.IllegalArgumentException(text);
> }
> public String getJavaInitializationString()
> {
> return "\""+getAsText()+"\"";
> }
> }
>
>
--
Thanks,
Rich Kulp
|
|
|
Re: V.E not writing the code returned by property editor --urgent :please help its [message #613346 is a reply to message #126176] |
Wed, 14 June 2006 16:31  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Here is an editor that works correctly for String[][]:
package t;
import java.beans.PropertyEditorSupport;
import java.util.ArrayList;
import java.util.List;
public class ContentTextEditor extends PropertyEditorSupport
{
public String getJavaInitializationString() {
Object value = getValue();
if (value == null)
return "null";
else {
StringBuffer b = new StringBuffer("new String[][] {");
String[][] sv = (String[][]) value;
for (int i = 0; i < sv.length; i++) {
if (i > 0)
b.append(',');
b.append('{');
String[] ssv = sv[i];
for (int j = 0; j < ssv.length; j++) {
if (j>0)
b.append(',');
b.append('"');
b.append(ssv[j]);
b.append('"');
}
b.append('}');
}
b.append('}');
return b.toString();
}
}
public String getAsText() {
Object value = getValue();
if (value == null)
return "null";
else if (value instanceof String[][]) {
StringBuffer sb = new StringBuffer();
String[][] v = (String[][]) value;
for (int i = 0; i < v.length; i++) {
String[] vv = v[i];
if (i>0)
sb.append('/');
for (int j = 0; j < vv.length; j++) {
if (j>0)
sb.append(',');
sb.append(vv[j]);
}
}
return sb.toString();
} else
return "???";
}
public void setAsText(String text) throws IllegalArgumentException {
List vl = new ArrayList();
int i = text.indexOf('/');
int b = 0;
while (i >= 0) {
vl.add(getSv(text.substring(b, i)));
b = i+1;
i = text.indexOf('/', b);
}
if (b<text.length())
vl.add(getSv(text.substring(b)));
setValue((String[][]) vl.toArray(new String[vl.size()][]));
}
private String[] getSv(String s) {
List vl = new ArrayList();
int i = s.indexOf(',');
int b = 0;
while (i >= 0) {
vl.add(s.substring(b, i));
b = i+1;
i = s.indexOf(',', b);
}
if (b<s.length())
vl.add(s.substring(b));
return (String[]) vl.toArray(new String[vl.size()]);
}
}
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.04573 seconds