New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added script support for ExtendedItem #1468
base: qrcode_feature
Are you sure you want to change the base?
Added script support for ExtendedItem #1468
Conversation
@claesrosell is this for 4.14? |
Not necessarily. I have no personal interest in that. I just decided to look into it since @hvbtup consider it important with script support for the QR-code things and I promised him long ago to take a look at it. I think it makes sense to wait with this until the QR-code extension is picked up again. |
Come to think about it: if RotatedText makes it into the 4.14 release, perhaps it would be good with this patch as well? |
I was ill last week (and still am). I'll need time to take a look at this. |
I tested, with partial success, but I think there's more to do. test_rotated_text_with_script.zip hat I would like to have is sth like this (for the RotatedTextItem):
Note: I think it is not necessary to show the available methods in auto completion, this is probably out of scope for anyway. But we want:
Current Status:
I looked at the code briefly. One of the main differences between When the When the |
With some changes (in fact quite a lot of) I am able to solve issue 2. That is, I am able to use See the attached diff.txt Not quite sure if it is a good idea, though. Issue 3 is much harder. What I have is a fake solution: But the implementation is a hack which is only working exactly for this example, by adding an additional method to
So, what is working for issue 3: Calling a Java method per Reflection (args matching in more complicated cases could be difficult, though). BTW I don't know if (with my changes) the chart scripting is still working; didn't test this. |
A rough idea how this could work: The plugin for the ExtendedItem could provide a factory method which would be called by Probably the original authors will say that all of this is already supported in the extension framework, but I have to admit that I don't grep how it works really. There are only 2 other extensions apart from the rotated text example: CrossTab and Chart. Both of them are by far too complicated to understand how they work or to serve as an example. |
A working solutionI created a branch on my repo: https://github.com/triestram-partner/birt/tree/Test-ExtendedItem-Script-Support The code is based on PR #1531. It seems to work, but I am not at all sure if the programming style is OK. What I did in addition to the changes I already mentioned yesterday: I created a new interface So this is not really complicated. What is not implementedAuto-completion for the available JS methods, e.g. for a Rotated Text Item, auto-completion does not offer Things to think about:In case of Not sure if the architecture is clean and good and in compliance with other BIRT code. Not sure if the same result could be achieved with a less invasive code change. I had to (trivially) change the CrossTab implementation due to the switch from Maybe you @claesrosell or others (@wimjongman, @speckyspooky) have suggestions for improving my working code. |
I'd appreciate if someone could take a look at my branch with a focus on the things I mentioned earlier regarding code quality etc. |
I will try to take a look into this later this week. Perhaps in the weekend. |
@@ -40,27 +40,41 @@ public static void handleOnPrepare(ExtendedItemHandle handle, ExecutionContext c | |||
|
|||
public static void handleOnCreate(ExtendedItemDesign design, IContent content, ExecutionContext context) { | |||
ExtendedItemHandle handle = (ExtendedItemHandle) design.getHandle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this item after the next if block. No need to get the handle if it is not used.
} | ||
} catch (Exception e) { | ||
addException(context, e, handle); | ||
} | ||
} | ||
|
||
public static void handleOnRender(ExtendedItemDesign design, IContent content, ExecutionContext context) { | ||
ExtendedItemHandle handle = (ExtendedItemHandle) design.getHandle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
BTW I spent some hours to find out how JS script auto-completion works, but I gave up. But I failed to do so.
just as a starting point (copied from the Chart item) and added this to plugin.xml:
But the extension manager fails to load this class and I don't know why. |
That was caused by a combination of two bugs in my code: First, I added the new class at the wrong place (tutorial_1 instead of tutorial_2) and I missed a level in the fully qualified class name in plugin.xml (BTW shouldn't the IDE provide better support here? I had to manually edit plugin.xml). |
What do you mean by auto completion? Is that CTRL+SPACE like we have in the editor? |
You don't even have to hit ctrl-space. |
Who takes care of that? Is it a js editor we pull in from webtools? |
I don't know, but all this is BIRT code, not from somewhere else. |
Just wanted to inform you that I spent some more afternoons with debugging, but I have to admit that I don't really understand what's going on. I was not able to add auto-completion support for the specific methods of the RotatedText item as an example and I give up for now. |
@hvbtup I am not that sharp with the scripting stuff, but these changes add script support for OnCreate and OnRender for all ExtendedItem. Do you think this is enough?