Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » How to create a null IJavaInstance instance?
How to create a null IJavaInstance instance? [message #137155] Wed, 11 April 2007 23:47 Go to next message
Allen Wang is currently offline Allen Wang
Messages: 28
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.

------=_NextPart_000_0024_01C77CF8.4D236F50
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hi, all!

I have a problem during my development now.. That is how to create a =
null IJavaInstance?

I want the VE to generate a statement by editing property editor like =
this:

myCustomizedText.setFormatter(new DateFormatter("dd/mm/yyyy"));

and I write a method to generate a IJavaInstance I want to set in the =
statement:

private IJavaInstance createObject(){
......

//strClass is the class name("DateFormatter", including package =
path), and initString is the init string of the class("DateFormatter")

return BeanUtilities.createJavaObject(strClass, =
JavaEditDomainHelper.getResourceSet(editDomain), =
BeanPropertyDescriptorAdapter.createAllocation(initString, editDomain));
}

and now I want to generate a statement like this:

myCustomizedText.setFormatter(null);

How to generate the "null" parameter?

I write a new method to generate this statement, but I come across some =
mistake.

=20
private IJavaInstance createObject(){
......

//strClass is the class name(including package)

return BeanUtilities.createJavaObject(strClass, =
JavaEditDomainHelper.getResourceSet(editDomain), =
InstantiationFactory.eINSTANCE.createParseTreeAllocation(Ins tantiationFac=
tory.eINSTANCE.createPTNullLiteral()));
}

The statement has been generated with a warning: =
java.lang.IllegalStateException(IWAV0190E: No bean instantiated for some =
reason);

What's wrong with my code? Why this warning appears? And how to generate =
the "null" parameter?

Appreciate for your help!

Thanks,
Hexise


------=_NextPart_000_0024_01C77CF8.4D236F50
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2900.3059" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi, all!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a problem during my development =
now.. That=20
is how to create a null IJavaInstance?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I want the VE to generate a statement =
by editing=20
property editor like this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3DArial>&nbsp;&nbsp;&nbsp; <FONT=20
color=3D#0000ff>myCustomizedText.setFormatter(<FONT color=3D#ff0000>new=20
DateFormatter("dd/mm/yyyy")</FONT>);</FONT></FONT></FONT ></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and I write a method to generate a=20
IJavaInstance&nbsp;I want to set in the statement:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; private =
IJavaInstance=20
createObject(){</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
.......</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
//strClass is=20
the class name("DateFormatter", including package path), and initString =
is the=20
init string of the class("DateFormatter")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
return=20
BeanUtilities.createJavaObject(strClass,&nbsp;JavaEditDo mainHelper.getRes=
ourceSet(editDomain),=20
BeanPropertyDescriptorAdapter.createAllocation(initString,=2 0
editDomain));</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and now I want to generate a statement =
like=20
this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3DArial>&nbsp;&nbsp;&nbsp; <FONT=20
color=3D#0000ff>myCustomizedText.setFormatter(<FONT=20
color=3D#ff0000>null</FONT>);</FONT></FONT></FONT></DIV >
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>How to generate the "null" =
parameter?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I write a new method to generate this =
statement,=20
but I come across some mistake.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; private =
IJavaInstance=20
createObject(){</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
.......</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
//strClass is=20
the class name(including package)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
return=20
BeanUtilities.createJavaObject(strClass,&nbsp;JavaEditDo mainHelper.getRes=
ourceSet(editDomain),=20
<FONT=20
color=3D#ff0000>InstantiationFactory.eINSTANCE.createParseTreeAllocation(=
InstantiationFactory.eINSTANCE.createPTNullLiteral())</FONT ><FONT=20
color=3D#000000>);</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The statement has been generated with a =
warning:=20
<FONT color=3D#0000ff>java.lang.IllegalStateException(IWAV0190E: No bean =

instantiated for some reason);</FONT></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What's wrong with my code? Why this =
warning=20
appears? And how to generate the "null" parameter?</FONT></DIV><FONT =
face=3DArial=20
size=3D2></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Appreciate for your help!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Hexise</FONT></DIV>
<DIV><BR></DIV></BODY></HTML>

------=_NextPart_000_0024_01C77CF8.4D236F50--
Re: How to create a null IJavaInstance instance? [message #137274 is a reply to message #137155] Mon, 16 April 2007 11:00 Go to previous messageGo to next message
Eclipse User
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Try returning just null. (Not the string but the value).

private IJavaInstance createObject() {
return null;
}

I'm not sure from your code who is calling createObject() so I'm not
sure if it can handle null. But in the rest of the VE, a null is used
for null IJavaInstance.

--
Thanks,
Rich Kulp
Re: How to create a null IJavaInstance instance? [message #137284 is a reply to message #137274] Mon, 16 April 2007 23:32 Go to previous messageGo to next message
Allen Wang is currently offline Allen Wang
Messages: 28
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C780E4.0FF85420
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hi, Rich,

I call the createObject() in=20

protected Object openDialogBox(Control cellEditorWindow){
return createObject(......);
}

It is a abstract method of DialogCellEditor, and my editor extends from =
DialogCellEditor.

And if I return null in openDialogBox() method, It seems nothing =
happened. I want the statement to be changed from =
myCustomizedText.setDataFormat("dd/mm/yyyy") to =
myCustomizedText.setDataFormat(null), or to delete this statement, but =
the myCustomizedText.setDataFormat("dd/mm/yyyy") statement still exists =
after I returned null in openDialogBox() method.

Did I miss something?

Best regards,
Hexise

"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message =
news:f00325$dtq$1@build.eclipse.org...
> Try returning just null. (Not the string but the value).
>=20
> private IJavaInstance createObject() {
> return null;
> }
>=20
> I'm not sure from your code who is calling createObject() so I'm not
> sure if it can handle null. But in the rest of the VE, a null is used
> for null IJavaInstance.
>=20
> --=20
> Thanks,
> Rich Kulp
------=_NextPart_000_0015_01C780E4.0FF85420
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2900.3059" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi, Rich,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I call the createObject() in =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>protected Object openDialogBox(Control=20
cellEditorWindow){</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; return=20
createObject(......);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>It is a abstract method of =
DialogCellEditor, and my=20
editor extends from DialogCellEditor.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>And if I return null in openDialogBox() =
method, It=20
seems nothing happened. I want the statement to be changed from <FONT=20
color=3D#0000ff>myCustomizedText.setDataFormat("dd/mm/yyyy ")</FONT> to =
<FONT=20
color=3D#0000ff>myCustomizedText.setDataFormat(null)</FONT >, or to =
delete this=20
statement, but the myCustomizedText.setDataFormat("dd/mm/yyyy") =
statement still=20
exists after I returned null in openDialogBox() method.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Did I miss something?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Best regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Hexise</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"Rich Kulp" &lt;</FONT><A=20
href=3D"mailto:richkulp@us.NO_SPAM.ibm.com"><FONT face=3DArial=20
size=3D2>richkulp@us.NO_SPAM.ibm.com</FONT></A><FONT face=3DArial =
size=3D2>&gt; wrote=20
in message </FONT><A href=3D"news:f00325$dtq$1@build.eclipse.org"><FONT =
face=3DArial=20
size=3D2>news:f00325$dtq$1@build.eclipse.org</FONT></A><FONT =
face=3DArial=20
size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; Try returning =
just null.=20
(Not the string but the value).<BR>&gt; <BR>&gt; private IJavaInstance=20
createObject() {<BR>&gt;&nbsp; return null;<BR>&gt; }<BR>&gt; <BR>&gt; =
I'm not=20
sure from your code who is calling createObject() so I'm not<BR>&gt; =
sure if it=20
can handle null. But in the rest of the VE, a null is used<BR>&gt; for =
null=20
IJavaInstance.<BR>&gt; <BR>&gt; -- <BR>&gt; Thanks,<BR>&gt; Rich=20
Kulp</FONT></BODY></HTML>

------=_NextPart_000_0015_01C780E4.0FF85420--
Re: How to create a null IJavaInstance instance? [message #137293 is a reply to message #137284] Tue, 17 April 2007 10:15 Go to previous message
Eclipse User
Originally posted by: richkulp.us.NO_SPAM.ibm.com

You are inheriting directly from JFace Dialog cell editor. The JFace
dialog cell editor doesn't allow null as a value. This is in the JFace
dialog cell editor:

public void widgetSelected(SelectionEvent event) {
// Remove the button's focus listener since it's guaranteed
// to lose focus when the dialog opens
button.removeFocusListener(getButtonFocusListener());

Object newValue = openDialogBox(editor);

// Re-add the listener once the dialog closes
button.addFocusListener(getButtonFocusListener());

if (newValue != null) {
boolean newValidState = isCorrect(newValue);


As you can see if the new value is null it is ignored.

I don't see a direct simple way around this other than in your
"myCustomizedTextClass" you do the following:

package mypackage;

public class CustomizedTextClass ... {

public static final String DEFAULT_DATA_FORMAT = "";

public void setDataFormat(String format) {
if (DEFAULT_DATA_FORMAT.equals(format)) {
... treat as you would of treated null
} else {
... do normal
}
}
}

Do not use null as DEFAULT_DATA_FORMAT, it won't work correctly in the
VE. The VE has a bug where if an initialization string evaluates to null
then it throws some errors. It expects an initialization string to
always evaluate to some value.

Then in your dialog cell editor return:

BeanUtilities.createJavaObject(strClass,
JavaEditDomainHelper.getResourceSet(editDomain),
BeanPropertyDescriptorAdapter.createAllocation("mypackage.CustomizedTextClass.DEFAULT_DATA_FORMAT ",
editDomain))


--
Thanks,
Rich Kulp
Re: How to create a null IJavaInstance instance? [message #615193 is a reply to message #137155] Mon, 16 April 2007 11:00 Go to previous message
Eclipse User
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Try returning just null. (Not the string but the value).

private IJavaInstance createObject() {
return null;
}

I'm not sure from your code who is calling createObject() so I'm not
sure if it can handle null. But in the rest of the VE, a null is used
for null IJavaInstance.

--
Thanks,
Rich Kulp
Re: How to create a null IJavaInstance instance? [message #615194 is a reply to message #137274] Mon, 16 April 2007 23:32 Go to previous message
Allen Wang is currently offline Allen Wang
Messages: 28
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C780E4.0FF85420
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hi, Rich,

I call the createObject() in=20

protected Object openDialogBox(Control cellEditorWindow){
return createObject(......);
}

It is a abstract method of DialogCellEditor, and my editor extends from =
DialogCellEditor.

And if I return null in openDialogBox() method, It seems nothing =
happened. I want the statement to be changed from =
myCustomizedText.setDataFormat("dd/mm/yyyy") to =
myCustomizedText.setDataFormat(null), or to delete this statement, but =
the myCustomizedText.setDataFormat("dd/mm/yyyy") statement still exists =
after I returned null in openDialogBox() method.

Did I miss something?

Best regards,
Hexise

"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message =
news:f00325$dtq$1@build.eclipse.org...
> Try returning just null. (Not the string but the value).
>=20
> private IJavaInstance createObject() {
> return null;
> }
>=20
> I'm not sure from your code who is calling createObject() so I'm not
> sure if it can handle null. But in the rest of the VE, a null is used
> for null IJavaInstance.
>=20
> --=20
> Thanks,
> Rich Kulp
------=_NextPart_000_0015_01C780E4.0FF85420
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2900.3059" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi, Rich,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I call the createObject() in =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>protected Object openDialogBox(Control=20
cellEditorWindow){</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; return=20
createObject(......);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>It is a abstract method of =
DialogCellEditor, and my=20
editor extends from DialogCellEditor.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>And if I return null in openDialogBox() =
method, It=20
seems nothing happened. I want the statement to be changed from <FONT=20
color=3D#0000ff>myCustomizedText.setDataFormat("dd/mm/yyyy ")</FONT> to =
<FONT=20
color=3D#0000ff>myCustomizedText.setDataFormat(null)</FONT >, or to =
delete this=20
statement, but the myCustomizedText.setDataFormat("dd/mm/yyyy") =
statement still=20
exists after I returned null in openDialogBox() method.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Did I miss something?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Best regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Hexise</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"Rich Kulp" &lt;</FONT><A=20
href=3D"mailto:richkulp@us.NO_SPAM.ibm.com"><FONT face=3DArial=20
size=3D2>richkulp@us.NO_SPAM.ibm.com</FONT></A><FONT face=3DArial =
size=3D2>&gt; wrote=20
in message </FONT><A href=3D"news:f00325$dtq$1@build.eclipse.org"><FONT =
face=3DArial=20
size=3D2>news:f00325$dtq$1@build.eclipse.org</FONT></A><FONT =
face=3DArial=20
size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; Try returning =
just null.=20
(Not the string but the value).<BR>&gt; <BR>&gt; private IJavaInstance=20
createObject() {<BR>&gt;&nbsp; return null;<BR>&gt; }<BR>&gt; <BR>&gt; =
I'm not=20
sure from your code who is calling createObject() so I'm not<BR>&gt; =
sure if it=20
can handle null. But in the rest of the VE, a null is used<BR>&gt; for =
null=20
IJavaInstance.<BR>&gt; <BR>&gt; -- <BR>&gt; Thanks,<BR>&gt; Rich=20
Kulp</FONT></BODY></HTML>

------=_NextPart_000_0015_01C780E4.0FF85420--
Re: How to create a null IJavaInstance instance? [message #615195 is a reply to message #137284] Tue, 17 April 2007 10:15 Go to previous message
Eclipse User
Originally posted by: richkulp.us.NO_SPAM.ibm.com

You are inheriting directly from JFace Dialog cell editor. The JFace
dialog cell editor doesn't allow null as a value. This is in the JFace
dialog cell editor:

public void widgetSelected(SelectionEvent event) {
// Remove the button's focus listener since it's guaranteed
// to lose focus when the dialog opens
button.removeFocusListener(getButtonFocusListener());

Object newValue = openDialogBox(editor);

// Re-add the listener once the dialog closes
button.addFocusListener(getButtonFocusListener());

if (newValue != null) {
boolean newValidState = isCorrect(newValue);


As you can see if the new value is null it is ignored.

I don't see a direct simple way around this other than in your
"myCustomizedTextClass" you do the following:

package mypackage;

public class CustomizedTextClass ... {

public static final String DEFAULT_DATA_FORMAT = "";

public void setDataFormat(String format) {
if (DEFAULT_DATA_FORMAT.equals(format)) {
... treat as you would of treated null
} else {
... do normal
}
}
}

Do not use null as DEFAULT_DATA_FORMAT, it won't work correctly in the
VE. The VE has a bug where if an initialization string evaluates to null
then it throws some errors. It expects an initialization string to
always evaluate to some value.

Then in your dialog cell editor return:

BeanUtilities.createJavaObject(strClass,
JavaEditDomainHelper.getResourceSet(editDomain),
BeanPropertyDescriptorAdapter.createAllocation("mypackage.CustomizedTextClass.DEFAULT_DATA_FORMAT ",
editDomain))


--
Thanks,
Rich Kulp
Previous Topic:problem with building VE from head
Next Topic:Modify property of multiple similar objects.
Goto Forum:
  


Current Time: Tue Jul 29 15:02:03 EDT 2014

Powered by FUDForum. Page generated in 0.03779 seconds