0

I am writing an extension for LibreOffifce. A tree with columns on my sidebar is needed. (example - https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html)

I found information about Tree Control and module "tree", e.g. here https://wiki.openoffice.org/wiki/Treecontrol https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/tree/module-ix.html

But I couldn't find anything about writing a tree with columns.

There is a quote "You can provide your own model which must at least support the interface com.sun.star.awt.XTreeModel." in the article "Tree control", but I also couldn't find any information about providing of my own models...

Please, help me find information and examples, if it is possible to provide tree with columns for LibreOffice extension.

1 Answer 1

0

Here is some Python-UNO code (as tagged in your question) that shows how to implement the XTreeDataModel UNO interface. You'll have to write a lot more code in order to render the nodes in multiple columns and do everything else you want. It may be required to create another class that implements XTreeNode.

import uno
import unohelper
from com.sun.star.awt.tree import XTreeDataModel

def myTree():
    document = XSCRIPTCONTEXT.getDocument()
    ctx = XSCRIPTCONTEXT.getComponentContext()
    smgr = ctx.getServiceManager()
    dlgprov = smgr.createInstanceWithArgumentsAndContext(
        "com.sun.star.awt.DialogProvider", (document,), ctx)
    dlg = dlgprov.createDialog(
        "vnd.sun.star.script:Standard.Dialog1?location=application")

    treeCtrl = dlg.getControl("TreeControl1")
    treeModel = treeCtrl.getModel()
    mutableTreeDataModel = smgr.createInstanceWithContext(
        "com.sun.star.awt.tree.MutableTreeDataModel", ctx)
    rootNode = mutableTreeDataModel.createNode("Root", True)  
    mutableTreeDataModel.setRoot(rootNode)
    myTree = MyTreeDataModel(rootNode)
    model = mutableTreeDataModel

    childNode1 = model.createNode("Parent 1", True)
    rootNode.appendChild(childNode1)   
    subChildNode = model.createNode("Child 1", True)
    childNode1.appendChild(subChildNode)

    treeModel.setPropertyValue("DataModel", myTree)
    dlg.execute()
    dlg.dispose()

class MyTreeDataModel(unohelper.Base, XTreeDataModel):
    def __init__(self, root):
        self.rootNode = root
  
    def getRoot(self):
        return self.rootNode

    def addTreeDataModelListener(self, listener):
        pass

    def removeTreeDataModelListener(self, listener):
        pass

More information for working with trees is at https://wiki.openoffice.org/wiki/Going_further_with_Dialog_and_Component#The_New_Tree_Control.

If it turns out that there is no convenient way to do this directly with UNO, I once did this with a JTreeTable in Java. LibreOffice extensions can be written in Java, so perhaps that would solve your needs instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.