简体   繁体   English

带列的 LibreOffice 树

[英]LibreOffice Tree with columns

I am writing an extension for LibreOffifce.我正在为 LibreOffifce 编写扩展程序。 A tree with columns on my sidebar is needed.我的侧边栏上需要一棵带有列的树。 (example - https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html ) (示例 - https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.ZFC35FDC70D5FC69D269883A822C7A53

I found information about Tree Control and module "tree", eg here https://wiki.openoffice.org/wiki/Treecontrol https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/tree/module-ix.html我找到了有关树控件和模块“树”的信息,例如这里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 .但我找不到任何关于用 columns 编写树的信息。

There is a quote "You can provide your own model which must at least support the interface com.sun.star.awt.XTreeModel."有一句名言“您可以提供自己的 model,它必须至少支持接口 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.如果可以为 LibreOffice 扩展提供带有列的树,请帮我查找信息和示例。

Here is some Python-UNO code (as tagged in your question) that shows how to implement the XTreeDataModel UNO interface.这是一些 Python-UNO 代码(在您的问题中标记),显示了如何实现XTreeDataModel UNO 接口。 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 .可能需要创建另一个实现 XTreeNode 的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 .有关使用树的更多信息, 请参见 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.如果事实证明没有方便的方法可以直接使用 UNO 执行此操作,我曾经在 Java 中使用 JTreeTable 执行此操作。 LibreOffice extensions can be written in Java, so perhaps that would solve your needs instead. LibreOffice 扩展可以用 Java 编写,所以也许这可以解决您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM