1*a4c7eb23SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a4c7eb23SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a4c7eb23SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a4c7eb23SAndrew Rist * distributed with this work for additional information 6*a4c7eb23SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a4c7eb23SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a4c7eb23SAndrew Rist * "License"); you may not use this file except in compliance 9*a4c7eb23SAndrew Rist * with the License. You may obtain a copy of the License at 10*a4c7eb23SAndrew Rist * 11*a4c7eb23SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a4c7eb23SAndrew Rist * 13*a4c7eb23SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a4c7eb23SAndrew Rist * software distributed under the License is distributed on an 15*a4c7eb23SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a4c7eb23SAndrew Rist * KIND, either express or implied. See the License for the 17*a4c7eb23SAndrew Rist * specific language governing permissions and limitations 18*a4c7eb23SAndrew Rist * under the License. 19*a4c7eb23SAndrew Rist * 20*a4c7eb23SAndrew Rist *************************************************************/ 21*a4c7eb23SAndrew Rist 22*a4c7eb23SAndrew Rist 23cdf0e10cSrcweir package complex.sfx2.tools; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 26cdf0e10cSrcweir import com.sun.star.frame.XController; 27cdf0e10cSrcweir import com.sun.star.frame.XDispatch; 28cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider; 29cdf0e10cSrcweir import com.sun.star.frame.XModel; 30cdf0e10cSrcweir import com.sun.star.lang.XComponent; 31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33cdf0e10cSrcweir import com.sun.star.util.URL; 34cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** 37cdf0e10cSrcweir * This class opens a given dialog in a separate Thread by dispatching an url 38cdf0e10cSrcweir * 39cdf0e10cSrcweir */ 40cdf0e10cSrcweir public class DialogThread extends Thread { 41cdf0e10cSrcweir public XComponent m_xDoc = null; 42cdf0e10cSrcweir public XMultiServiceFactory m_xMSF = null; 43cdf0e10cSrcweir public String m_url = ""; 44cdf0e10cSrcweir DialogThread(XComponent xDoc, XMultiServiceFactory msf, String url)45cdf0e10cSrcweir public DialogThread(XComponent xDoc, XMultiServiceFactory msf, String url) { 46cdf0e10cSrcweir this.m_xDoc = xDoc; 47cdf0e10cSrcweir this.m_xMSF = msf; 48cdf0e10cSrcweir this.m_url = url; 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir @Override run()52cdf0e10cSrcweir public void run() { 53cdf0e10cSrcweir XModel aModel = UnoRuntime.queryInterface( XModel.class, m_xDoc ); 54cdf0e10cSrcweir 55cdf0e10cSrcweir XController xController = aModel.getCurrentController(); 56cdf0e10cSrcweir 57cdf0e10cSrcweir //Opening Dialog 58cdf0e10cSrcweir try { 59cdf0e10cSrcweir XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, xController.getFrame() ); 60cdf0e10cSrcweir XURLTransformer xParser = UnoRuntime.queryInterface( XURLTransformer.class, 61cdf0e10cSrcweir m_xMSF.createInstance( "com.sun.star.util.URLTransformer" ) ); 62cdf0e10cSrcweir 63cdf0e10cSrcweir // Because it's an in/out parameter 64cdf0e10cSrcweir // we must use an array of URL objects. 65cdf0e10cSrcweir URL[] aParseURL = new URL[1]; 66cdf0e10cSrcweir aParseURL[0] = new URL(); 67cdf0e10cSrcweir aParseURL[0].Complete = m_url; 68cdf0e10cSrcweir xParser.parseStrict(aParseURL); 69cdf0e10cSrcweir 70cdf0e10cSrcweir URL aURL = aParseURL[0]; 71cdf0e10cSrcweir XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", com.sun.star.frame.FrameSearchFlag.SELF | 72cdf0e10cSrcweir com.sun.star.frame.FrameSearchFlag.CHILDREN); 73cdf0e10cSrcweir PropertyValue[] dispatchArguments = new PropertyValue[0]; 74cdf0e10cSrcweir 75cdf0e10cSrcweir if (xDispatcher != null) { 76cdf0e10cSrcweir xDispatcher.dispatch(aURL, dispatchArguments); 77cdf0e10cSrcweir } else { 78cdf0e10cSrcweir System.out.println("xDispatcher is null"); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 81cdf0e10cSrcweir System.out.println("Couldn't open dialog"); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir } 84cdf0e10cSrcweir }