Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 301341 - XWT Control creation notification
Summary: XWT Control creation notification
Status: CLOSED FIXED
Alias: None
Product: XWT
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-30 16:27 EST by Konstantin Scheglov CLA
Modified: 2013-01-24 15:31 EST (History)
1 user (show)

See Also:


Attachments
Support for postCreation0() and tweak for Element (5.95 KB, patch)
2010-01-31 04:26 EST, Konstantin Scheglov CLA
no flags Details | Diff
Support for postCreation0() and tweak for Element (rev 2) (6.21 KB, patch)
2010-01-31 07:55 EST, Konstantin Scheglov CLA
no flags Details | Diff
Support for postCreation0() and tweak for Element (rev 3) (6.59 KB, patch)
2010-02-01 08:45 EST, Konstantin Scheglov CLA
no flags Details | Diff
Support for postCreation0() and tweak for Element (rev 4) (5.03 KB, patch)
2010-04-13 09:56 EDT, Konstantin Scheglov CLA
john.arthorne: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Scheglov CLA 2010-01-30 16:27:12 EST
Build Identifier: M20090917-0800

I would like to have something like ILoadedAction, but with extended functionality. Something like:
ICreatedAction {
  onCreated(String pathInXML, Object sender);
}
Where "pathInXML" is "/" separated String on XML element names from root element. I need it to recognize Control or Viewer in my own copy of parsed XML. You may also use array of strings or list of them, no matter, I just need some XWT internals independent way to associated created components with elements in XML.

And "sender" is created Control, Viewer, Item or any other Widget.
Notification should be sent directly after component instance creation, before applying any property. So, I would able to get default values for all properties.

Reproducible: Always
Comment 1 Konstantin Scheglov CLA 2010-01-30 16:33:26 EST
Ah...
I think that just Control/Widget is not enough.
I would like to have this notification for any created Object.
For example creation of Layout or LayoutData is also interesting thing.
Comment 2 Yves YANG CLA 2010-01-30 19:26:38 EST
Hi,

XWT have provided a solution to use your own XWTLoader. You need to create a subclass of ResourceLoader and extend it for your purpose. Of course, you need to register it in XWT before using it.

We need more information to understand the requirement and the benefices to implement it as standard solution.
Comment 3 Konstantin Scheglov CLA 2010-01-31 04:25:44 EST
1. Right now ResourceLoader has no protected method which is called directly after "targetObject" creation. Nearest method which it has is "postCreation()", but it is called after applying attributes and creating children. I need to process just created component without applying attributes.

2. I've added new method into ResourceLoader, so my subclass can implement it:
/**
 * This method is invoked directly after creation of component instance, but
 * before applying its attributes and creating children.
 */
protected void postCreation0(Object target) {
	// TODO
}
  How can I configure XWT to use my ResourceLoader subclass?

  Something like this?

IXWTLoader activeLoader = XWTLoaderManager.getActive();
Core profile = new Core(new IElementLoaderFactory() {
	public IVisualElementLoader createElementLoader(IRenderingContext context, IXWTLoader loader) {}, activeLoader);
XWT.applyProfile(profile);

3. I've added tweaks into Element, Attribute and their creation to remember original tag names, to be able to find corresponding XML element in my copy of XML tree.
Comment 4 Konstantin Scheglov CLA 2010-01-31 04:26:51 EST
Created attachment 157709 [details]
Support for postCreation0() and tweak for Element
Comment 5 Konstantin Scheglov CLA 2010-01-31 07:55:12 EST
Created attachment 157714 [details]
Support for postCreation0() and tweak for Element (rev 2)

Shell creation handled specially in ResourceLoader, so this patch includes also Shell object processing.
Comment 6 Konstantin Scheglov CLA 2010-02-01 08:45:53 EST
Created attachment 157777 [details]
Support for postCreation0() and tweak for Element (rev 3)

I found that just using names of elements is not enough, because it is possible that we will have more than one Button in Shell, so we can not distinguish them by name. We should use indexes.

So, patch was modified to remember index instead of name in Element.
Comment 7 Yves YANG CLA 2010-02-08 19:24:16 EST
Thanks for the contribution. 
The modification is committed in Head -> 20100209. I leave the bug open, please check it out and close it if the fix works.
Comment 8 Konstantin Scheglov CLA 2010-02-09 04:03:36 EST
Almost. :-)

I see two little problems:

1. Do you use Element.getOriginalIndex1() instead of Element.getOriginalIndex() intentionally or this is just mistype?

2. English is not my native language, but I see now in compare that I did obvious mistype in JavaDoc for this method. "the index of this element is its parent" -> "the index of this element in its parent".
Comment 9 Yves YANG CLA 2010-02-17 19:52:03 EST
The modifications in the last patch are validated and committed in Head -> 20100217
Comment 10 Konstantin Scheglov CLA 2010-04-13 09:55:02 EDT
I've found problem with using "originalIndex" in Element.
It does not work very good when nested properties.
---
<Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt">
	<Shell.layout>
		<RowLayout/>
	</Shell.layout>
	<TableViewer>
		<TableViewer.table headerVisible="true" linesVisible="true">
			<TableViewer.table.layoutData>
				<RowData width="326" height="207"/>
			</TableViewer.table.layoutData>
		</TableViewer.table>
	</TableViewer>
</Shell>
---

  In this example "TableViewer.table.layoutData" has "TableViewer" as parent, not "TableViewer.table" as I would expect. But it renders just fine, so I should just adopt to this. To do this, I would like to replace "originalIndex" with "path", which we have in any case already in ElementHandler. To minimize memory overhead, I store it as String.
Comment 11 Konstantin Scheglov CLA 2010-04-13 09:56:31 EDT
Created attachment 164714 [details]
Support for postCreation0() and tweak for Element (rev 4)

Can you review and apply this patch?
Comment 12 Yves YANG CLA 2010-04-19 16:50:50 EDT
Apply the patch and committed -> 20100419