Share

Metawidget

Subscribe

Init null object

  1. 2008-07-11 12:51:13 UTC
    Richard,
    I have to questions:
    1 : In the current version (0.55) if we have an object witch is null, in MW window only the label of the object appear . Is it possible in this case to put a button("init"). And when you click on it it instanciate the object with the default constructor and refresh the MW window.

    2: Something linked with the first question. Is it possible to have some conditional object.
    I try to explain with an example.
    I have an object Figure with some Field (name, ..., haveLegend, and Legend of type Legend)
    haveLegend is a boolean. What i want if have legend is true : MW show the legend part) and whent it's false or is disable it or it remove it.
    A must will to be able to declare it in the xml file : condition="haveLegend=true"

    Thanks in advance

    Regards

    Thierry
  2. 2008-07-12 09:03:24 UTC
    Thierry,

    In reverse order:

    2. Metawidget is all about re-using *existing* technologies, so I'm not keen on inventing an expression language (EL) such as 'haveLegend=true'. Swing doesn't have an EL, but many of the other environments do. For Swing, this sort of thing would best be handled by a custom Inspector. You'd write an Inspector and add it to your CompositeInspector. The Inspector would say 'if field x is null, then set field y to be hidden'. See MetawidgetAnnotationInspector for an example of inspecting a field to see if it's null (eg. UiLookup.onlyIfNull).

    1. Sort of. Not everybody would want this so it's not the 'generic' case. And there are a few different ways you could do it (most cleanly, using the method described in 2 above). However, here's a quick way:

    public class Main
    {
    public static void main( String[] args )
    {
    // Data model

    final Foo foo = new Foo();

    // Metawidget

    final SwingMetawidget metawidget = new SwingMetawidget();
    metawidget.setInspector( new PropertyTypeInspector() );
    metawidget.setToInspect( foo );

    if ( foo.bar == null )
    {
    final JButton button = new JButton();
    button.setAction( new AbstractAction( "init" ) {

    @Override
    public void actionPerformed( ActionEvent e )
    {
    foo.bar = new Bar();
    metawidget.remove( button );
    metawidget.repaint();
    }

    } );
    button.setName( "bar" );
    metawidget.add( button );
    }

    // JFrame

    JFrame frame = new JFrame( "Metawidget Tutorial" );
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.getContentPane().add( metawidget );
    frame.setSize( 400, 210 );
    frame.setVisible( true );
    }

    public static class Foo
    {
    public String name;

    public Bar bar;
    }

    public static class Bar
    {
    public String baz;
    }
    }
  3. 2008-07-14 06:10:14 UTC
    Thierry,

    I have written a JexlInspector (using Commons JEXL) to help you with point 2. It's in SVN, and I have sent a compiled JAR to your e-mail address for you to try.

    I'd be interested to hear how you go,

    Richard.
  4. 2008-07-28 15:56:41 UTC
    Richard,
    I'm soory for my late reply i was in wacation for 2 weeks
    Thanks for your answers
    I'll test the JexlInspector this week

    Regards,

    Thierry
  5. 2008-07-29 00:03:21 UTC
    Thierry,

    Thanks for that. Inspired by your original message, I'm working on a feature for Metawidget v0.6 that'll allow you to do...

    @UiAction
    @UiJexlAttribute( name = "hidden", value = "${!contactDialog.readOnly}" )
    public void edit() {
    ...

    ...and it'll generate a JButton labelled 'edit', tied to the edit() method, provided the JEXL expression doesn't hide it. You can use @UiAction (a Metawidget annotation) or @Action (from Swing AppFramework).

    So I'll be very interested to hear how you go with the JexlInspector support so far, as it is shaping up to be an important part of the next release.

    Regards,

    Richard.
  6. 2008-07-29 16:35:30 UTC
    Richard,
    Thank's for all you hard work.
    I don't received your email
    I try with the svn source by the annotation @UiJexlAttribute class is not present in the svn.



    Another point not related to this
    I think it's a bug
    When i use the tabbed pane mode for the presentation ( with the section keyword) when we modify edited objet in the UI the part of the object in the tabbedpane are not updated after the save() method and it work with the default behaviour.

    Regards,

    Thierry
  7. 2008-07-30 00:27:19 UTC
    Thierry,

    It IS present in SVN, so you may need to do something with your SVN client. It's here:

    http://metawidget.svn.sourceforge.net/viewvc/metawidget/trunk/src/java/org/metawidget/inspector/jexl

    With regards to the tabs, I'm going to need you to send me an example. I tried adding '.setParameter( "sectionStyle", TableGridBagLayout.SECTION_AS_TAB )' to the ContactDialog.java of the Swing Address Book example, and it seems to work okay for me? I can add notes under the 'Notes' tab and they get saved correctly?

    Regards,

    Richard.
  8. 2008-07-30 15:48:00 UTC
    Richard,
    I'am sorry for not finding UiJexlAttribute my IDE missed it.
    All work fine now ...

    The JexlInspector work well the component is hiden conditionally

    But what i espect (I don't know if is possible) is to dynamically hide/show it when condition is filled (for example when a checkbox is check/uncheck)


    Regards

    Thierry
  9. 2008-07-30 23:04:03 UTC
    Thierry,

    > The JexlInspector work well the component is hiden conditionally

    Great!

    > But what i expect (I don't know if is possible) is to dynamically hide/show it when condition is filled

    Interesting. You have a couple of options, and I'd appreciate you exploring them and giving me some feedback on which works best.

    1. Re-call 'setToInspect' whenever the condition changes. You could use UpdateStrategy.READ_WRITE (as mentioned before), and in your propertyChangeListener trigger a 'setToInspect'. This will make Metawidget redraw the UI, allowing big changes (like hiding a whole group of fields and methods)

    2. If the change is quite small, you could use BeansBinding to toggle the 'visibility' property of the JComponents you want to hide. You'd call 'setToInspect', then 'SwingMetawidget.getComponent( "foo" )', and having gotten the component you can manually hook up BeansBinding

    If 2) works for you, we can probably add a BeansBindingInspector to automate the process a bit. As a favour, it'd be really great if you could write a blog of your explorations.

    Regards,

    Richard.
  10. 2008-08-01 23:17:03 UTC
    Richard

    Thanks for yours suggestions

    I undertand your proposition 1 and 2 they are very interesting. But we don't find an easy way to test them.
    What is not clear for me and my student is how to track the object change. As I understand Beans Binding track only changes at property levels.
    We have made some test to track some change at property level : IE we had a fireEventChange in the property setter and add an event listener to the object. It work well but it a bit difficult to add this fire event on each property.
    In this blog entry http://weblogs.java.net/blog/fabriziogiudici/archive/2008/01/beansbinding_no.html a solution is proposed to automate that (see in the comments part). I don't know if we miss something in the use of BeansBinding or MW but apparantly there are not mecanism to listen object change.

    I'm in vacation for 3 weeks. So I'll write a blog when i'll come back

    Thanks for your hard time.

    Regards,

    Thierry
  11. 2008-09-30 13:12:06 UTC
    Thierry,

    Just to let you know this feature has been included in the newly released Metawidget v0.6. I've also included a Swing AppFramework-based example that demonstrates it being used.

    I'd be most grateful if you could download it and let me know if it works for you.

    Regards,

    Richard.
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.