Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » How add restriction to delete a component
How add restriction to delete a component [message #902234] Thu, 16 August 2012 09:23 Go to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
Hi,

I need to validate if a component can be deleted, how can I do this?

Is a parameter in *.wbp-component.xml ?

Thks
Re: How add restriction to delete a component [message #902239 is a reply to message #902234] Thu, 16 August 2012 09:39 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 554
Registered: July 2009
Senior Member
Nobody needed this yet.
So, no.

But it should be pretty easy to add into org.eclipse.wb.core.model.JavaInfo.canDelete()


Konstantin Scheglov,
Google, Inc.
Re: How add restriction to delete a component [message #902244 is a reply to message #902239] Thu, 16 August 2012 09:58 Go to previous messageGo to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
What need to implement in JavaInfo?

I think to just override the method, but is final Sad
Re: How add restriction to delete a component [message #902246 is a reply to message #902244] Thu, 16 August 2012 10:03 Go to previous messageGo to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
To implement, I create a method in JavaInfo that the canDelete() calls, than in my "ClassObjectInfo" I override it. Yes?
Re: How add restriction to delete a component [message #902250 is a reply to message #902246] Thu, 16 August 2012 10:26 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 554
Registered: July 2009
Senior Member
I've added support for "canDelete" script into JavaInfo.
Committed into SVN trunk.


Konstantin Scheglov,
Google, Inc.
Re: How add restriction to delete a component [message #902252 is a reply to message #902250] Thu, 16 August 2012 10:41 Go to previous messageGo to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
It's avaiable to download now?

I access http://dev.eclipse.org/viewcvs/viewvc.cgi/trunk/org.eclipse.wb.core/src/org/eclipse/wb/core/model/JavaInfo.java?root=TOOLS_WINDOWBUILDER&view=log and dont't found...

It's in another url?
Re: How add restriction to delete a component [message #902253 is a reply to message #902252] Thu, 16 August 2012 10:46 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 554
Registered: July 2009
Senior Member
No idea.
I see current source here.
http://dev.eclipse.org/svnroot/tools/org.eclipse.windowbuilder/trunk/org.eclipse.wb.core/src/org/eclipse/wb/core/model/JavaInfo.java
Look for "canDelete".


Konstantin Scheglov,
Google, Inc.
Re: How add restriction to delete a component [message #902254 is a reply to message #902253] Thu, 16 August 2012 10:49 Go to previous messageGo to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
Ok,

I've download it, and now I'll see how use it...

Thks
Re: How add restriction to delete a component [message #902270 is a reply to message #902254] Thu, 16 August 2012 12:51 Go to previous messageGo to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
I implement this on *.wbp-component.xml
<parameter name="canDelete">isComponentType(object.getParent(),'com.test.fw.wb.mvc.core.VerticalBox')</parameter>


I saw that in the variable object, the script put the Info object, in org.eclipse.wb.internal.core.model.JavaInfoUtils.executeScript(JavaInfo, String)

Is wrong what I've done? Because always return false.

To understand, the object just can be deleted if it parent is a VerticalBox...
Re: How add restriction to delete a component [message #902273 is a reply to message #902270] Thu, 16 August 2012 13:41 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 554
Registered: July 2009
Senior Member
IIRC "isComponentType" is available only for flow/simple containers.
And if there is any error in "canDelete" script, we consider this as "false".


In other scripts you have only ReflectionUtils class.
But actually all this can be done using ReflectionUtils, see org.eclipse.wb.internal.core.model.generic.ContainerObjectValidators.DEF_functions

  private static final String DEF_functions = StringUtils.join(new String[]{
      "def isModelType(model, c) {",
      "  if (c is String) {",
      "    return ReflectionUtils.isSuccessorOf((Class) model.description.componentClass, c);",
      "  } else {",
      "    return c.isAssignableFrom(model.description.componentClass);",
      "  }",
      "};",
      "def isSuccessorOf(o, c) {",
      "  if (c is String) {",
      "    return ReflectionUtils.isSuccessorOf(o, c);",
      "  } else {",
      "    return o != null && c.isAssignableFrom(o.getClass());",
      "  }",
      "};",
      "def isComponentType(c) {",
      "  return isModelType(component, c);",
      "};",
      "def isReferenceType(c) {",
      "  return isModelType(reference, c);",
      "};",
      "def isContainerType(c) {",
      "  return isModelType(container, c);",
      "};",
      "def isContainerThis() {",
      "  return isSuccessorOf(container.creationSupport, "
          + "'org.eclipse.wb.internal.core.model.creation.ThisCreationSupport');",
      "};",}, "\n");


Konstantin Scheglov,
Google, Inc.

[Updated on: Thu, 16 August 2012 13:41]

Report message to a moderator

Re: How add restriction to delete a component [message #902275 is a reply to message #902273] Thu, 16 August 2012 13:55 Go to previous messageGo to next message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
Ok..

I saw the source code and the default value and the return if it not found the script, shouldn't be true? Actually is false, but if it don't find it return false, and the canDelete() return false without verify the other conditions...

And how can I make de restriction, I don't understand what you say...
It's worng this:
<parameter name="canDelete"><![CDATA[
			isComponentType(object.getParent(),"com.test.fw.wb.mvc.core.VerticalBox")]]>
		</parameter>
Re: How add restriction to delete a component [message #902278 is a reply to message #902275] Thu, 16 August 2012 14:04 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 554
Registered: July 2009
Senior Member
Thank you for catching this bug.
Yes, we should return "true" if there are no script.
Fixed in trunk.

May be something like
ReflectionUtils.isSuccessorOf(object.parent, 'com.test.fw.wb.mvc.core.VerticalBox')

Not tested.


Konstantin Scheglov,
Google, Inc.
Re: How add restriction to delete a component [message #902284 is a reply to message #902278] Thu, 16 August 2012 14:24 Go to previous message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
Ok..!

I try this and it is working...!

Thank you, one more time...
Re: How add restriction to delete a component [message #902622 is a reply to message #902239] Thu, 16 August 2012 09:58 Go to previous message
Arthur Fücher is currently offline Arthur Fücher
Messages: 59
Registered: August 2012
Member
What need to implement in JavaInfo?

I think to just override the method, but is final :(
Previous Topic:Can't use WindowBuilder in Eclipse 3.7 with Xming
Next Topic:Re: How add restriction to delete a component
Goto Forum:
  


Current Time: Thu Apr 17 00:07:55 EDT 2014

Powered by FUDForum. Page generated in 0.01854 seconds