1

Groupbox expand and collapse icons [closed]

asked 2013-02-07 14:29:07 +0800

RetoH gravatar image RetoH flag of Switzerland
44 5

updated 2013-02-07 14:30:36 +0800

Hi, I would like to find an application wide solution to get open/closed icons in all groupbox captions.

There is a proposed solution in the Demo: http://www.zkoss.org/zkdemo/layout/group_box

And another here: http://emrpms.blogspot.ch/2012/05/group-box-with-collapse-and-expand.html

But both solutions require me to copy/paste a lot of stuff all over the place. I only want to define this once.

This works (instead of setLabel I plan to use setImage later on):

  <groupbox onOpen='self.getFirstChild().setLabel(self.isOpen() ? "Open" : "Closed")' >
    <caption label="Caption" />

  </groupbox>

But when I try to define this attribute value in the language add-on, it does not work:

<language-addon>    
  <addon-name>myapp</addon-name>
  <language-name>xul/html</language-name>        
  <component>
    <component-name>groupbox</component-name>
    <extends>groupbox</extends>
    <custom-attribute>
      <attribute-name>onOpen</attribute-name>
      <attribute-value>self.getFirstChild().setLabel(self.isOpen() ? "Open" : "Closed")</attribute-value>
    </custom-attribute>
  </component>
</language-addon>

Is it not possible to define event code in the language add on?

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by dennis
close date 2013-02-19 04:45:51

Comments

1

regardless the answer, onOpen is a event, and custom-attribute is the attribute by component.setAttribute(), they are totally different.

dennis ( 2013-02-08 04:45:52 +0800 )edit

good to know, that was just a naive assumption on my part, because in the zk demo they have zul markup like this: <attribute name="onOpen"><![CDATA[cb.setChecked(self.isOpen());]]></attribute>

RetoH ( 2013-02-08 14:45:41 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-02-08 04:55:08 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

updated 2013-02-08 04:57:46 +0800

Here is my example

zk.xml

<zk>
    <language-config>
        <addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
    </language-config>
</zk>

lang-addon.xml

<language-addon>
    <addon-name>simple</addon-name>
    <depends>zul</depends>
    <language-name>xul/html</language-name>

    <component>
        <component-name>groupboxex</component-name>
        <component-class>simple.GroupboxEx</component-class>
        <extends>groupbox</extends>
    </component>
</language-addon>

GroupboxEx.java

package simple;

import org.zkoss.zk.ui.event.OpenEvent;
import org.zkoss.zul.Caption;
import org.zkoss.zul.Groupbox;

public class GroupboxEx extends Groupbox{

    private static final long serialVersionUID = 1L;


    public void onOpen(OpenEvent evt){
        Caption cp = getCaption();
        if(cp!=null){
            cp.setLabel(evt.isOpen()?"Open":"Close");
        }
    }

}

demo.zul

<vlayout spacing="15px">
    <hbox spacing="15px">
        <groupboxex width="300px">
            <caption label="Open"/>
            ABCD
        </groupboxex>
    </hbox>
</vlayout>
link publish delete flag offensive edit

Comments

if this answer solve your question, please vote and mark the answer is correct.

dennis ( 2013-02-08 04:57:04 +0800 )edit

Thank you dennis . I learned new stuff today :)

Senthilchettyin ( 2013-02-08 05:32:38 +0800 )edit

yes this did solve my question, thanks a lot. I also had to set the 3d mold in the constructor. I figured out that I need to provide an explicit setter which delegates to the super class if I want to be able to specify a library property in the zk.xml.

RetoH ( 2013-02-08 15:07:22 +0800 )edit

Question tools

Follow
3 followers

RSS

Stats

Asked: 2013-02-07 14:29:07 +0800

Seen: 69 times

Last updated: Feb 08 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More