113efc523SAndrew Rist /************************************************************** 2*a98dafebSmseidel * 313efc523SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 413efc523SAndrew Rist * or more contributor license agreements. See the NOTICE file 513efc523SAndrew Rist * distributed with this work for additional information 613efc523SAndrew Rist * regarding copyright ownership. The ASF licenses this file 713efc523SAndrew Rist * to you under the Apache License, Version 2.0 (the 813efc523SAndrew Rist * "License"); you may not use this file except in compliance 913efc523SAndrew Rist * with the License. You may obtain a copy of the License at 10*a98dafebSmseidel * 1113efc523SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a98dafebSmseidel * 1313efc523SAndrew Rist * Unless required by applicable law or agreed to in writing, 1413efc523SAndrew Rist * software distributed under the License is distributed on an 1513efc523SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1613efc523SAndrew Rist * KIND, either express or implied. See the License for the 1713efc523SAndrew Rist * specific language governing permissions and limitations 1813efc523SAndrew Rist * under the License. 19*a98dafebSmseidel * 2013efc523SAndrew Rist *************************************************************/ 2113efc523SAndrew Rist 2213efc523SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.wiki; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.awt.XControl; 27cdf0e10cSrcweir import com.sun.star.awt.XControlContainer; 28cdf0e10cSrcweir import com.sun.star.awt.XControlModel; 29cdf0e10cSrcweir import com.sun.star.awt.XDialog; 30cdf0e10cSrcweir import com.sun.star.awt.XDialogEventHandler; 31cdf0e10cSrcweir import com.sun.star.awt.XDialogProvider2; 329ecc082cSAriel Constenla-Haile import com.sun.star.awt.XAnimation; 33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 34cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 35cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 36cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 37cdf0e10cSrcweir import com.sun.star.awt.XTopWindow; 38cdf0e10cSrcweir import com.sun.star.awt.XTopWindowListener; 39cdf0e10cSrcweir import com.sun.star.awt.XWindow; 40cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 41cdf0e10cSrcweir import com.sun.star.lang.EventObject; 42cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 43cdf0e10cSrcweir 44cdf0e10cSrcweir public class WikiDialog implements XDialogEventHandler, XTopWindowListener 45*a98dafebSmseidel { 46cdf0e10cSrcweir XComponentContext m_xContext; 47cdf0e10cSrcweir XControlContainer m_xControlContainer; 48cdf0e10cSrcweir XDialog m_xDialog; 49cdf0e10cSrcweir String[] m_aMethods; 50cdf0e10cSrcweir boolean m_bAction = false; 51cdf0e10cSrcweir Settings m_aSettings; 52*a98dafebSmseidel 53cdf0e10cSrcweir protected Thread m_aThread; 54cdf0e10cSrcweir protected boolean m_bThreadFinished = false; 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** Creates a new instance of WikiDialog */ WikiDialog(XComponentContext c, String DialogURL)58cdf0e10cSrcweir public WikiDialog(XComponentContext c, String DialogURL) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir this.m_xContext = c; 61cdf0e10cSrcweir XMultiComponentFactory xMCF = m_xContext.getServiceManager(); 62cdf0e10cSrcweir m_aSettings = Settings.getSettings(m_xContext); 63cdf0e10cSrcweir try 64cdf0e10cSrcweir { 65cdf0e10cSrcweir Object obj; 66cdf0e10cSrcweir obj = xMCF.createInstanceWithContext("com.sun.star.awt.DialogProvider2", m_xContext ); 67cdf0e10cSrcweir XDialogProvider2 xDialogProvider = (XDialogProvider2) UnoRuntime.queryInterface( XDialogProvider2.class, obj ); 68*a98dafebSmseidel 69cdf0e10cSrcweir m_xDialog = xDialogProvider.createDialogWithHandler( DialogURL, this ); 70cdf0e10cSrcweir m_xControlContainer = (XControlContainer)UnoRuntime.queryInterface( XControlContainer.class, m_xDialog ); 71cdf0e10cSrcweir XTopWindow xTopWindow = (XTopWindow)UnoRuntime.queryInterface( XTopWindow.class, m_xDialog ); 72cdf0e10cSrcweir if ( xTopWindow != null ) 73cdf0e10cSrcweir xTopWindow.addTopWindowListener( this ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir catch (com.sun.star.uno.Exception ex) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir ex.printStackTrace(); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80*a98dafebSmseidel ThreadStop( boolean bSelf )81cdf0e10cSrcweir public synchronized void ThreadStop( boolean bSelf ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir if ( bSelf || m_aThread != null && !m_bThreadFinished ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir try 86cdf0e10cSrcweir { 87cdf0e10cSrcweir Helper.AllowConnection( bSelf ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir catch( Exception ex ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir ex.printStackTrace(); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir m_aThread = null; 96cdf0e10cSrcweir m_bThreadFinished = true; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir setMethods(String [] Methods)99*a98dafebSmseidel protected void setMethods (String [] Methods) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir this.m_aMethods = Methods; 102cdf0e10cSrcweir } 103*a98dafebSmseidel 104*a98dafebSmseidel show( )105*a98dafebSmseidel public boolean show( ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir m_bThreadFinished = false; 108cdf0e10cSrcweir 109cdf0e10cSrcweir if( m_xDialog != null ) m_xDialog.execute(); 110cdf0e10cSrcweir return m_bAction; 111cdf0e10cSrcweir } 112*a98dafebSmseidel 113*a98dafebSmseidel getSupportedMethodNames()114*a98dafebSmseidel public String[] getSupportedMethodNames() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir return m_aMethods; 117cdf0e10cSrcweir } 118*a98dafebSmseidel 119*a98dafebSmseidel callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )120cdf0e10cSrcweir public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir return true; 123cdf0e10cSrcweir } 124*a98dafebSmseidel SetTitle( String sTitle )125cdf0e10cSrcweir public void SetTitle( String sTitle ) 126cdf0e10cSrcweir throws Exception 127cdf0e10cSrcweir { 128cdf0e10cSrcweir SetTitle( m_xDialog, sTitle ); 129cdf0e10cSrcweir } 130*a98dafebSmseidel SetTitle( XDialog xDialog, String sTitle )131cdf0e10cSrcweir public static void SetTitle( XDialog xDialog, String sTitle ) 132cdf0e10cSrcweir throws Exception 133cdf0e10cSrcweir { 134cdf0e10cSrcweir if ( xDialog != null && sTitle != null ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir XControl xDialogControl = (XControl)UnoRuntime.queryInterface( XControl.class, xDialog ); 137cdf0e10cSrcweir if ( xDialogControl != null ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xDialogControl.getModel() ); 140cdf0e10cSrcweir if ( xPropSet != null ) 141cdf0e10cSrcweir xPropSet.setPropertyValue( "Title", sTitle ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145*a98dafebSmseidel GetPropSet(String sControl)146cdf0e10cSrcweir protected XPropertySet GetPropSet(String sControl) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir return GetPropSet( m_xControlContainer, sControl ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir GetPropSet( XControlContainer xControlContainer, String sControl )151cdf0e10cSrcweir protected static XPropertySet GetPropSet( XControlContainer xControlContainer, String sControl ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir XPropertySet xPS = null; 154cdf0e10cSrcweir 155cdf0e10cSrcweir if ( xControlContainer != null && sControl != null ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir XControl xControl = xControlContainer.getControl(sControl); 158cdf0e10cSrcweir xPS = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel() ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir if ( xPS == null ) 162cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException(); 163*a98dafebSmseidel 164cdf0e10cSrcweir return xPS; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir CreateSimpleDialog( XComponentContext xContext, String sURL, int nTitleID, String[] pControls, int[] pStringIDs )167cdf0e10cSrcweir public static XDialog CreateSimpleDialog( XComponentContext xContext, String sURL, int nTitleID, String[] pControls, int[] pStringIDs ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir XDialog xResult = null; 170cdf0e10cSrcweir 171cdf0e10cSrcweir if ( xContext != null && sURL != null && sURL.length() > 0 ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir try 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Object oDialogProvider = xContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider2", xContext ); 176cdf0e10cSrcweir XDialogProvider2 xDialogProvider = (XDialogProvider2) UnoRuntime.queryInterface( XDialogProvider2.class, oDialogProvider ); 177*a98dafebSmseidel 178cdf0e10cSrcweir if ( xDialogProvider != null ) 179cdf0e10cSrcweir xResult = xDialogProvider.createDialog( sURL ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir if ( xResult != null ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir SetTitle( xResult, Helper.GetLocalizedString( xContext, nTitleID ) ); 184cdf0e10cSrcweir if ( pControls != null && pStringIDs != null && pControls.length == pStringIDs.length ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir XControlContainer xControlContainer = (XControlContainer)UnoRuntime.queryInterface( XControlContainer.class, xResult ); 187cdf0e10cSrcweir for ( int nInd = 0; nInd < pControls.length; nInd++ ) 188cdf0e10cSrcweir GetPropSet( xControlContainer, pControls[nInd] ).setPropertyValue( "Label", new Integer( pStringIDs[nInd] ) ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192cdf0e10cSrcweir catch (Exception ex) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir ex.printStackTrace(); 195cdf0e10cSrcweir } 196*a98dafebSmseidel } 197cdf0e10cSrcweir 198cdf0e10cSrcweir return xResult; 199cdf0e10cSrcweir } 200*a98dafebSmseidel InsertThrobber( int X, int Y, int Width, int Height )201cdf0e10cSrcweir protected void InsertThrobber( int X, int Y, int Width, int Height ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir try 204cdf0e10cSrcweir { 205cdf0e10cSrcweir XControl xDialogControl = ( XControl ) UnoRuntime.queryInterface( XControl.class, m_xDialog ); 206cdf0e10cSrcweir XControlModel xDialogModel = null; 207cdf0e10cSrcweir if ( xDialogControl != null ) 208cdf0e10cSrcweir xDialogModel = xDialogControl.getModel(); 209cdf0e10cSrcweir 210cdf0e10cSrcweir XMultiServiceFactory xDialogFactory = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class, xDialogModel ); 211cdf0e10cSrcweir if ( xDialogFactory != null ) 212cdf0e10cSrcweir { 2139ecc082cSAriel Constenla-Haile XControlModel xThrobberModel = (XControlModel)UnoRuntime.queryInterface( XControlModel.class, xDialogFactory.createInstance( "com.sun.star.awt.SpinningProgressControlModel" ) ); 214cdf0e10cSrcweir XPropertySet xThrobberProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xThrobberModel ); 215cdf0e10cSrcweir if ( xThrobberProps != null ) 216cdf0e10cSrcweir { 217*a98dafebSmseidel xThrobberProps.setPropertyValue( "Name", "WikiThrobber" ); 218cdf0e10cSrcweir xThrobberProps.setPropertyValue( "PositionX", new Integer( X ) ); 219cdf0e10cSrcweir xThrobberProps.setPropertyValue( "PositionY", new Integer( Y ) ); 220*a98dafebSmseidel xThrobberProps.setPropertyValue( "Width", new Integer( Width ) ); 221*a98dafebSmseidel xThrobberProps.setPropertyValue( "Height", new Integer( Height ) ); 222cdf0e10cSrcweir 223cdf0e10cSrcweir XNameContainer xDialogContainer = (XNameContainer)UnoRuntime.queryInterface( XNameContainer.class, xDialogModel ); 224cdf0e10cSrcweir xDialogContainer.insertByName( "WikiThrobber", xThrobberModel ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir } 228cdf0e10cSrcweir catch( Exception e ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir e.printStackTrace(); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir SetThrobberVisible( false ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir SetThrobberActive( boolean bActive )236cdf0e10cSrcweir public void SetThrobberActive( boolean bActive ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir if ( m_xControlContainer != null ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir try 241cdf0e10cSrcweir { 2429ecc082cSAriel Constenla-Haile XAnimation xThrobber = (XAnimation)UnoRuntime.queryInterface( XAnimation.class, m_xControlContainer.getControl( "WikiThrobber" ) ); 243cdf0e10cSrcweir if ( xThrobber != null ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir if ( bActive ) 2469ecc082cSAriel Constenla-Haile xThrobber.startAnimation(); 247cdf0e10cSrcweir else 2489ecc082cSAriel Constenla-Haile xThrobber.stopAnimation(); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir } 251cdf0e10cSrcweir catch( Exception e ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir e.printStackTrace(); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir SetThrobberVisible( boolean bVisible )258cdf0e10cSrcweir public void SetThrobberVisible( boolean bVisible ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir if ( m_xControlContainer != null ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir try 2639ecc082cSAriel Constenla-Haile { 264cdf0e10cSrcweir XWindow xWindow = (XWindow)UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( "WikiThrobber" ) ); 265cdf0e10cSrcweir if ( xWindow != null ) 266cdf0e10cSrcweir xWindow.setVisible( bVisible ); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir catch ( Exception e ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir e.printStackTrace(); 271cdf0e10cSrcweir } 2729ecc082cSAriel Constenla-Haile } 273cdf0e10cSrcweir } 274cdf0e10cSrcweir SetFocusTo( String aControl )275cdf0e10cSrcweir public void SetFocusTo( String aControl ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir if ( m_xControlContainer != null ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir try 280*a98dafebSmseidel { 281cdf0e10cSrcweir XWindow xWindow = (XWindow)UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( aControl ) ); 282cdf0e10cSrcweir if ( xWindow != null ) 283cdf0e10cSrcweir xWindow.setFocus(); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir catch ( Exception e ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir e.printStackTrace(); 288cdf0e10cSrcweir } 289*a98dafebSmseidel } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir DisposeDialog()292cdf0e10cSrcweir public void DisposeDialog() 293cdf0e10cSrcweir { 294cdf0e10cSrcweir Helper.Dispose( m_xDialog ); 295cdf0e10cSrcweir } 296*a98dafebSmseidel windowOpened( EventObject e )297cdf0e10cSrcweir public void windowOpened( EventObject e ) 298cdf0e10cSrcweir {} 299cdf0e10cSrcweir windowClosing( EventObject e )300cdf0e10cSrcweir public void windowClosing( EventObject e ) 301cdf0e10cSrcweir {} 302cdf0e10cSrcweir windowClosed( EventObject e )303cdf0e10cSrcweir public void windowClosed( EventObject e ) 304cdf0e10cSrcweir {} 305cdf0e10cSrcweir windowMinimized( EventObject e )306cdf0e10cSrcweir public void windowMinimized( EventObject e ) 307cdf0e10cSrcweir {} 308cdf0e10cSrcweir windowNormalized( EventObject e )309cdf0e10cSrcweir public void windowNormalized( EventObject e ) 310cdf0e10cSrcweir {} 311cdf0e10cSrcweir windowActivated( EventObject e )312cdf0e10cSrcweir public void windowActivated( EventObject e ) 313cdf0e10cSrcweir {} 314cdf0e10cSrcweir windowDeactivated( EventObject e )315cdf0e10cSrcweir public void windowDeactivated( EventObject e ) 316cdf0e10cSrcweir {} 317*a98dafebSmseidel disposing( EventObject e )318cdf0e10cSrcweir public void disposing( EventObject e ) 319cdf0e10cSrcweir {} 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322