Thread Locked This thread is locked - replies are not allowed.


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 30 - Pages: 3 [ Previous | 1 2 3 | Next ] - Last Post: 13 Jun 22, 22:42 Last Post By: RobM Threads: [ Previous | Next ]
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Template page: get file base name
Posted: 7 Jun 22, 16:20   in response to: RobM in response to: RobM
 
No worries Rob :-)

(Missing an overloaded method by not matching everything is common. To avoid this problem, you can use the@Override annotation in compiled code.)
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 7 Jun 22, 21:12   in response to: davidekholm in response to: davidekholm
 
It is partially working now I have corrected the code
class AboutUI extends JWebPageUI{
  public void setAlbumObject(AlbumObject ao) {
    super.setAlbumObject(ao);
    System.out.println("setting ao " + ao);
    System.out.println("setting currentAO " + currentAO);
    //Rest of the control panel code
  }
}
If I'm in edit mode and move from one object to the template I always get:
setting ao Defaults.htt
setting currentAO Defaults.htt

However, if I Quit and restart, then open the template from explore mode I get:
First time opening
setting ao Defaults.htt
setting currentAO Defaults.htt

Second and subsequent openings (or open after exiting edit mode)
setting ao null
setting currentAO null
setting ao Defaults.htt
setting currentAO Defaults.htt
JeffTucker

Posts: 8,455
Registered: 31-Jan-2006
Re: Template page: get file base name
Posted: 7 Jun 22, 21:20   in response to: RobM in response to: RobM
 
That's because you have improperly instantiated a mutable type without correctly overriding the encapsulation, thereby creating an implicitly cast abstraction.

I think I'm getting the hang of this stuff.
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 7 Jun 22, 21:38   in response to: JeffTucker in response to: JeffTucker
 
JeffTucker wrote:
That's because you have improperly instantiated a mutable type without correctly overriding the encapsulation, thereby creating an implicitly cast abstraction.

I think I'm getting the hang of this stuff.

Of course, why didn't I see that! I just need to invoke an instance of interocitor.
JeffTucker

Posts: 8,455
Registered: 31-Jan-2006
Re: Template page: get file base name
Posted: 7 Jun 22, 22:43   in response to: RobM in response to: RobM
 
RobM wrote:
I just need to invoke an instance of interocitor.

Only if you're using Metaluna Java.
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 9 Jun 22, 00:55   in response to: RobM in response to: RobM
 
I might have gone off-piste but this works reliably. Is it a safe way to do it?
class AboutUI extends JWebPageUI {
JAlbumContext uiContext = JAlbumContext.getInstance();
JAlbumExplorer je = uiContext.getExplorer();
JEditPanel jep = je.editor;
AlbumObject currentAO = jep.getAO();
JButton saveAsDefault = new JButton("Save as default");
JButton loadDefaults = new JButton("Load defaults");
...


Edited by: RobM on 9 Jun 2022, 00:05
As long as I wrap the code after 'AlbumObject currentAO = jep.getAO();' in a test for null, otherwise on Make album it errors with currentAO as null
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Template page: get file base name
Posted: 9 Jun 22, 11:43   in response to: RobM in response to: RobM
 
RobM wrote:
I might have gone off-piste but this works reliably. Is it a safe way to do it?
class AboutUI extends JWebPageUI {
JAlbumContext uiContext = JAlbumContext.getInstance();
JAlbumExplorer je = uiContext.getExplorer();
JEditPanel jep = je.editor;
AlbumObject currentAO = jep.getAO();
JButton saveAsDefault = new JButton("Save as default");
JButton loadDefaults = new JButton("Load defaults");
...

Edited by: RobM on 9 Jun 2022, 00:05
As long as I wrap the code after 'AlbumObject currentAO = jep.getAO();' in a test for null, otherwise on Make album it errors with currentAO as null


No, that's too cumbersome. Why don't you simply do a null-check for currentAO? jAlbum does pass null as parameter when you leave an edited page, but a simple null check should do.
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 9 Jun 22, 22:48   in response to: davidekholm in response to: davidekholm
 
Not sure what has happened overnight but now the template variables are not being saved to the project's .info file. Time to call time on this endeavour, at least for a while. Thanks for the help.
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 10 Jun 22, 23:12   in response to: RobM in response to: RobM
 
I have tried every way of checking for and avoiding ao being null and it always fails either on opening/closing the template, making the album with/without the template being open.

The only way I can make it work is to get the editor context, write the control panel and then reference currentAO within an action listener. This way currentAO is always not null when loading/saving defaults.

It might be cumbersome but it works. I'll add the functionality to Missive skin then if anyone else is interested they can try my method or see if they have more luck than me.

David, thanks again, I really do appreciate your help.
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Template page: get file base name
Posted: 11 Jun 22, 12:21   in response to: RobM in response to: RobM
 
Rob, please reiterate for me, the purpose of this template file, then attach the current one and I'll see what can be done.
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 11 Jun 22, 13:57   in response to: davidekholm in response to: davidekholm
 
Attachment Defaults.htt (10.4 KB)
davidekholm wrote:
Rob, please reiterate for me, the purpose of this template file, then attach the current one and I'll see what can be done.
The idea is for a user to fill in all of the settings for a template page, say the About.htt, and save those settings and any comment to a defaults folder in the configuration directory. The user can then choose to load the defaults in other projects using the same skin family, instead of having to re-enter the data manually or use my Copy template data from one project to another.

The template has load and save defaults buttons in addition to the content entries. The currentAO usage is in blocks of code saveAsDefault (line 59) and loadDefaults (94). Ideally currentAO should always give the template as the object, not null or the previous object, then the load/save can share common code.

Attached is my test template, Defaults.htt, (an about page template). Try it in Missive skin.
It works, but there are still a few improvements to be made (minor and not related to the current object being null or the wrong object I have experienced).
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 12 Jun 22, 01:07   in response to: RobM in response to: RobM
 
Attachment Defaults.htt (10.8 KB)
I have it working without invoking the Explorer and Editor or even overriding setAlbumObject. It all works as long as I keep the use of currentAO within the action listeners of the load/save buttons.

Attached is the current file, which I can't quite believe is actually working.

Of course, I have no idea why the code works inside the action listener but not immediately before it.
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Template page: get file base name
Posted: 13 Jun 22, 12:47   in response to: RobM in response to: RobM
 
RobM wrote:

Of course, I have no idea why the code works inside the action listener but not immediately before it.

Immediately before the actionListener, then you're in the constructor of and instance of that class and at that time "currentAO" isn't set yet. This happens when jAlbum calls "setAlbumObject()".
RobM

Posts: 4,379
Registered: 4-Aug-2006
Re: Template page: get file base name
Posted: 13 Jun 22, 12:57   in response to: davidekholm in response to: davidekholm
 
davidekholm wrote:
RobM wrote:

Of course, I have no idea why the code works inside the action listener but not immediately before it.

Immediately before the actionListener, then you're in the constructor of and instance of that class and at that time "currentAO" isn't set yet. This happens when jAlbum calls "setAlbumObject()".

It’s a kind of magic ;)
I almost have the code condensed to a single method called by the load/save buttons. It then becomes very easy to add the functionality to any skin/template. It should make it much easier for template users.

We finally got there, despite my best efforts at overly complicating things.
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Template page: get file base name
Posted: 13 Jun 22, 14:16   in response to: RobM in response to: RobM
 
Great!
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums