Hi Антон,

On Sat, May 03, 2014 at 07:09:47PM +0400, Антон Борисов wrote:
> Hi all,
> I have dialog created by DialogProvider2 and xdl file created in Form
> Designer, and i want to add Hyperlink to this dialog by java code, because
> there is no ability to add it in Form Designer.
> 
>                     XDialog dialog  = ...
>                     XControl dialogControl = ..
>                     XControlModel dialogControlModel = ...
>                     XNameContainer xNameContainer =
> QI.XNameContainer(dialogControlModel);
> 
>                     Object o =
> getxMCF().createInstanceWithContext("com.sun.star.awt.UnoControlFixedHyperlink",
> m_xContext);
>                     XControl hyperlinkControl = QI.XControl(o);
>                     Object model =
> QI.XMultiServiceFactory(QI.XControl(dialog).getModel()).createInstance("com.sun.star.awt.UnoControlFixedHyperlinkModel");
>                     XControlModel hyperLinkControlModel =
> QI.XControlModel(model);
>                     hyperlinkControl.setModel(hyperLinkControlModel);
> 
>                     XFixedHyperlink xFixedHyperlink =
> QI.XFixedHyperlink(hyperlinkControl);
>                     // ... setting url and text
> 
>                     XPropertySet xPropertySet =
> QI.XPropertySet(hyperLinkControlModel);
> 
>                     xPropertySet.setPropertyValue("PositionX", new
> Integer(100));
>                     xPropertySet.setPropertyValue("PositionY", new
> Integer(200));
> 
>                     xNameContainer.insertByName("hyperLink",
> hyperLinkControlModel);
> 
>                     QI.XControlContainer(dialog).addControl("hyperLink",
> hyperlinkControl);
>                     dialog.execute();
> 
> This have no effect, hyperlink positioned in left upper corner of dialog
> 
> Maybe it's possible to add hyperlink control to xdl file manually without
> Form Designer?
> 
> If it is not possible what am i doing wrong?

A few things, please compare with the attached code, it is much simpler:

- create the control model at the dialog model factory
- set the control model properties
- insert the control model in the dialog model container
- get the control from the dialog control
- ...


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina
/**************************************************************
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 *************************************************************/
package org.apache.openoffice.demo;

import com.sun.star.awt.DialogProvider;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlContainer;
import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XDialog;
import com.sun.star.awt.XDialogProvider;
import com.sun.star.awt.XFixedHyperlink;
import com.sun.star.beans.XMultiPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.container.XNameContainer;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ariel
 */
public class DialogClientApplication {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext != null) {
                DialogClientApplication demo = new 
DialogClientApplication(xContext);
                demo.run();
            }
        } catch (BootstrapException e) {
            
Logger.getLogger(DialogClientApplication.class.getName()).log(Level.SEVERE, 
e.getMessage());
        } finally {
            System.exit(0);
        }
    }

    private final XComponentContext m_xContext;

    private DialogClientApplication(XComponentContext xContext) {
        m_xContext = xContext;
    }

    private void run() {
        try {
            XDialogProvider xDialogProvider = DialogProvider.create(m_xContext);
            XDialog xDialog = 
xDialogProvider.createDialog("vnd.sun.star.expand:$OOO_BASE_DIR/share/basic/Euro/DlgPassword.xdl");
            XControl xControl = UnoRuntime.queryInterface(XControl.class, 
xDialog);
            XControlContainer xControlContainer = 
UnoRuntime.queryInterface(XControlContainer.class, xDialog);

            XControlModel xControlModel = xControl.getModel();
            XNameContainer xNameContainer = 
UnoRuntime.queryInterface(XNameContainer.class, xControlModel);
            XMultiServiceFactory xModelFactory = 
UnoRuntime.queryInterface(XMultiServiceFactory.class, xControlModel);

            final String sControlName = "UnoControlFixedHyperlinkModel";
            XMultiPropertySet xPropertySet = UnoRuntime.queryInterface(
                    XMultiPropertySet.class,
                    
xModelFactory.createInstance("com.sun.star.awt.UnoControlFixedHyperlinkModel"));
            xPropertySet.setPropertyValues(
                    new String[]{"Height", "Label", "Name", "PositionX", 
"PositionY", "URL", "Width"},
                    new Object[]{
                        8,
                        "Apache OpenOffice",
                        sControlName,
                        6,
                        65 - 6 - 8,
                        "https://www.openoffice.org";,
                        100
                    });
            xNameContainer.insertByName(sControlName, xPropertySet);
            XFixedHyperlink xFixedHyperlink = UnoRuntime.queryInterface(
                    XFixedHyperlink.class,
                    xControlContainer.getControl(sControlName));
            // ...

            short nResult = xDialog.execute();

        } catch (IllegalArgumentException ex) {
            
Logger.getLogger(DialogClientApplication.class.getName()).log(Level.SEVERE, 
null, ex);
        } catch (Exception ex) {
            
Logger.getLogger(DialogClientApplication.class.getName()).log(Level.SEVERE, 
null, ex);
        }
    }

}

Attachment: pgpVVr9bgmpvZ.pgp
Description: PGP signature

Reply via email to