1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package complex.sfx2.tools; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.frame.XController; 31 import com.sun.star.frame.XDispatch; 32 import com.sun.star.frame.XDispatchProvider; 33 import com.sun.star.frame.XModel; 34 import com.sun.star.lang.XComponent; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.uno.UnoRuntime; 37 import com.sun.star.util.URL; 38 import com.sun.star.util.XURLTransformer; 39 40 /** 41 * This class opens a given dialog in a separate Thread by dispatching an url 42 * 43 */ 44 public class DialogThread extends Thread { 45 public XComponent m_xDoc = null; 46 public XMultiServiceFactory m_xMSF = null; 47 public String m_url = ""; 48 49 public DialogThread(XComponent xDoc, XMultiServiceFactory msf, String url) { 50 this.m_xDoc = xDoc; 51 this.m_xMSF = msf; 52 this.m_url = url; 53 } 54 55 @Override 56 public void run() { 57 XModel aModel = UnoRuntime.queryInterface( XModel.class, m_xDoc ); 58 59 XController xController = aModel.getCurrentController(); 60 61 //Opening Dialog 62 try { 63 XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, xController.getFrame() ); 64 XURLTransformer xParser = UnoRuntime.queryInterface( XURLTransformer.class, 65 m_xMSF.createInstance( "com.sun.star.util.URLTransformer" ) ); 66 67 // Because it's an in/out parameter 68 // we must use an array of URL objects. 69 URL[] aParseURL = new URL[1]; 70 aParseURL[0] = new URL(); 71 aParseURL[0].Complete = m_url; 72 xParser.parseStrict(aParseURL); 73 74 URL aURL = aParseURL[0]; 75 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", com.sun.star.frame.FrameSearchFlag.SELF | 76 com.sun.star.frame.FrameSearchFlag.CHILDREN); 77 PropertyValue[] dispatchArguments = new PropertyValue[0]; 78 79 if (xDispatcher != null) { 80 xDispatcher.dispatch(aURL, dispatchArguments); 81 } else { 82 System.out.println("xDispatcher is null"); 83 } 84 } catch (com.sun.star.uno.Exception e) { 85 System.out.println("Couldn't open dialog"); 86 } 87 } 88 }