Setting listeners on a treeControl with Java macros

Creating a macro - Writing a Script - Using the API

Setting listeners on a treeControl with Java macros

Postby Psycrow » Thu Sep 18, 2008 3:34 pm

Hi there,

I have managed to build a TreeControl in a dialog box, but I still don't know how I can add listeners on that tree.
The tree displays well in the dialog, nodes expand, collapse, etc ...
In fact I am able to add a listener to the implementation of the XMutableTreeDataModel interface, but it's not sufficient for my goals.

As I have seen on the API documentation, http://api.openoffice.org/docs/common/ref/com/sun/star/awt/tree/XTreeControl.html there is tools to implements all kind of listeners linked to the treeControl. This is my problem : how do I use that class ?

Here is my Tree class, wich use a Dialog class you may find here :
http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=3813 (look for the code section titled "Dialog.java")

Here is the code of my Tree class
Code: Select all   Expand viewCollapse view
/**
*
*/
package hm.ooo.tools;

import com.sun.star.awt.XControlModel;
import com.sun.star.awt.tree.TreeDataModelEvent;
import com.sun.star.awt.tree.XMutableTreeDataModel;
import com.sun.star.awt.tree.XMutableTreeNode;
import com.sun.star.awt.tree.XTreeControl;
import com.sun.star.awt.tree.XTreeDataModelListener;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.script.provider.XScriptContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

/**
* @author bmartinez
*/
public class Tree implements XTreeDataModelListener {

   private XComponentContext xComponentContext;
   private XMutableTreeDataModel xMutableTreeDataModel;
   private XMultiComponentFactory xMultiComponentFactory;
   private XMultiServiceFactory xDialogMSF;
   private Object treeControl;
   private XTreeControl xTreeControl;
   private XMutableTreeNode root;
   private Dialog dialog;

   private XScriptContext xsc;

   /**
    * Construit un nouvel arbre vide (contient seulement une racine) et l'inclue dans une boite de dialogue <code>Dialog</code>.
    * @param xsc le contexte UNO du document.
    * @param dialog la boite de dialogue qui présente l'arbre
    * @throws Exception
    */
   public Tree(XScriptContext xsc, Dialog dialog) throws Exception {
      // Logger
      //
      Logger.init(xsc);
      this.xsc = xsc;
      this.dialog = dialog;
      Logger.output("Initialisation");
      xComponentContext = xsc.getComponentContext();
      xMultiComponentFactory = xComponentContext.getServiceManager();
      xDialogMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xMultiComponentFactory);
      init();
   }

   /**
    * Initialise l'arbre au sein de la boite de dialogue qui doit le présenter.
    * @param dialog la boite de dialogue qui présente l'arbre
    * @throws Exception
    */
   private void init() throws Exception {

      // On crée les datas de l'arbre
      //
      Object treeData = xMultiComponentFactory.createInstanceWithContext("com.sun.star.awt.tree.MutableTreeDataModel", xComponentContext);
      xMutableTreeDataModel = (XMutableTreeDataModel) UnoRuntime.queryInterface(XMutableTreeDataModel.class, treeData);

      // On lui ajoute un Listener
      //
      xMutableTreeDataModel.addTreeDataModelListener(this);

      // On crée la racine de l'arbre dans les datas
      //
      root = xMutableTreeDataModel.createNode("Racine", true);
      root.setDataValue("TreeView");
      xMutableTreeDataModel.setRoot(root);
      Logger.output(xMutableTreeDataModel.getRoot().getDisplayValue().toString());

      // On crée un model d'arbre rattaché au dialog
      //
      xDialogMSF = dialog.getXMultiComponentFactoryDialogModel();
      XControlModel xTreeControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, xDialogMSF
            .createInstance("com.sun.star.awt.tree.TreeControlModel"));

//********************************************************************************************************************
//* Here is the control wich would allow me to add all the lsteners I need, but I haven't found a way yet to link it to my tree :(
//********************************************************************************************************************
      // On crée l'arbre (sa partie graphique)
      //
      // treeControl = xMultiComponentFactory.createInstanceWithContext("com.sun.star.awt.tree.TreeControl", xComponentContext);
      // xTreeControl = (XTreeControl) UnoRuntime.queryInterface(XTreeControl.class, treeControl);

      // On crée ses propriétés
      //
      XPropertySet xTreeControlModelSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTreeControlModel);

      // On définie ses propriétés
      //
      xTreeControlModelSet.setPropertyValue("SelectionType", com.sun.star.view.SelectionType.SINGLE);
      xTreeControlModelSet.setPropertyValue("PositionX", new Integer(3));
      xTreeControlModelSet.setPropertyValue("PositionY", new Integer(3));
      xTreeControlModelSet.setPropertyValue("Width", new Integer(128));
      xTreeControlModelSet.setPropertyValue("Height", new Integer(256));
      xTreeControlModelSet.setPropertyValue("DataModel", xMutableTreeDataModel); // On lie les datas au modèle
      xTreeControlModelSet.setPropertyValue("ShowsRootHandles", new Boolean(true));
      xTreeControlModelSet.setPropertyValue("ShowsHandles", new Boolean(true));
      xTreeControlModelSet.setPropertyValue("RootDisplayed", new Boolean(true));
      xTreeControlModelSet.setPropertyValue("Editable", new Boolean(false));
      xTreeControlModelSet.setPropertyValue("Name", new String("MyTree"));

      // On associe le treecontrol à la boite de dialogue passée en paramètre
      //
      dialog.getXDialogModelNameContainer().insertByName("MyTree", xTreeControlModel);
   }

   /*
    * (non-Javadoc)
    * @see com.sun.star.lang.XEventListener#disposing(com.sun.star.lang.EventObject)
    */
   public void disposing(EventObject p_arg0) {
      // TODO Auto-generated method stub

   }

   /*
    * (non-Javadoc)
    * @see com.sun.star.awt.tree.XTreeDataModelListener#treeNodesChanged(com.sun.star.awt.tree.TreeDataModelEvent)
    */
   public void treeNodesChanged(TreeDataModelEvent p_arg0) {
      Logger.output("treeNodesChanged");
   }

   /*
    * (non-Javadoc)
    * @see com.sun.star.awt.tree.XTreeDataModelListener#treeNodesInserted(com.sun.star.awt.tree.TreeDataModelEvent)
    */
   public void treeNodesInserted(TreeDataModelEvent p_arg0) {
      Logger.output("treeNodesInserted :" + p_arg0.Source.toString());
   }

   /*
    * (non-Javadoc)
    * @see com.sun.star.awt.tree.XTreeDataModelListener#treeNodesRemoved(com.sun.star.awt.tree.TreeDataModelEvent)
    */
   public void treeNodesRemoved(TreeDataModelEvent p_arg0) {
      Logger.output("treeNodesRemoved");
   }

   /*
    * (non-Javadoc)
    * @see com.sun.star.awt.tree.XTreeDataModelListener#treeStructureChanged(com.sun.star.awt.tree.TreeDataModelEvent)
    */
   public void treeStructureChanged(TreeDataModelEvent p_arg0) {
      Logger.output("treeStructureChanged");

   }

}


I thank you by advance for your help, I hope that the forum comunity will compensate the poor API documentation I have seen so far....
OOo 3.0.X on Mac OSx Leopard + M$WindowsXP @work
Psycrow
 
Posts: 9
Joined: Tue Jul 29, 2008 10:43 am
Location: South of France

Re: Setting listeners on a treeControl with Java macros

Postby supernam » Fri Jun 01, 2018 12:23 pm

Hi Psycrow ,
Excuse me. Have you solved this problem now? I am developing a tree view right now.
OpenOffice 1.4 on Linux
supernam
 
Posts: 8
Joined: Thu Jan 04, 2018 9:08 am

Re: Setting listeners on a treeControl with Java macros

Postby robleyd » Fri Jun 01, 2018 1:18 pm

Don't be disappointed if the OP doesn't respond; that user hasn't been on the forum for nearly ten years.
Cheers
David
Apache OpenOffice Developer Build 4.2.0 9820 - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2932
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Setting listeners on a treeControl with Java macros

Postby supernam » Mon Jun 04, 2018 3:44 am

OK! I'm just trying, I only found a little bit of information about java in this forum.
OpenOffice 1.4 on Linux
supernam
 
Posts: 8
Joined: Thu Jan 04, 2018 9:08 am

Re: Setting listeners on a treeControl with Java macros

Postby robleyd » Mon Jun 04, 2018 4:29 am

Please don't ask the same question in multiple topics.
Cheers
David
Apache OpenOffice Developer Build 4.2.0 9820 - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2932
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia


Return to Macros and UNO API

Who is online

Users browsing this forum: JeJe and 4 guests