| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
|
| 19 |
package com.sun.star.wiki; |
| 20 |
|
| 21 |
import com.sun.star.awt.XControl; |
| 22 |
import com.sun.star.awt.XControlContainer; |
| 23 |
import com.sun.star.awt.XControlModel; |
| 24 |
import com.sun.star.awt.XDialog; |
| 25 |
import com.sun.star.awt.XDialogEventHandler; |
| 26 |
import com.sun.star.awt.XDialogProvider2; |
| 27 |
import com.sun.star.awt.XAnimation; |
| 28 |
import com.sun.star.beans.XPropertySet; |
| 29 |
import com.sun.star.lang.XMultiComponentFactory; |
| 30 |
import com.sun.star.uno.UnoRuntime; |
| 31 |
import com.sun.star.uno.XComponentContext; |
| 32 |
import com.sun.star.awt.XTopWindow; |
| 33 |
import com.sun.star.awt.XTopWindowListener; |
| 34 |
import com.sun.star.awt.XWindow; |
| 35 |
import com.sun.star.container.XNameContainer; |
| 36 |
import com.sun.star.lang.EventObject; |
| 37 |
import com.sun.star.lang.XMultiServiceFactory; |
| 38 |
|
| 39 |
public class WikiDialog implements XDialogEventHandler, XTopWindowListener |
| 40 |
{ |
| 41 |
protected XComponentContext m_xContext; |
| 42 |
private XControlContainer m_xControlContainer; |
| 43 |
protected XDialog m_xDialog; |
| 44 |
private String[] m_aMethods; |
| 45 |
protected boolean m_bAction = false; |
| 46 |
protected Settings m_aSettings; |
| 47 |
protected Thread m_aThread; |
| 48 |
protected boolean m_bThreadFinished = false; |
| 49 |
|
| 50 |
|
| 51 |
/** Creates a new instance of WikiDialog */ |
| 52 |
public WikiDialog(XComponentContext c, String DialogURL) |
| 53 |
{ |
| 54 |
this.m_xContext = c; |
| 55 |
XMultiComponentFactory xMCF = m_xContext.getServiceManager(); |
| 56 |
m_aSettings = Settings.getSettings(m_xContext); |
| 57 |
try |
| 58 |
{ |
| 59 |
Object obj; |
| 60 |
obj = xMCF.createInstanceWithContext("com.sun.star.awt.DialogProvider2", m_xContext ); |
| 61 |
XDialogProvider2 xDialogProvider = UnoRuntime.queryInterface( XDialogProvider2.class, obj ); |
| 62 |
|
| 63 |
m_xDialog = xDialogProvider.createDialogWithHandler( DialogURL, this ); |
| 64 |
m_xControlContainer = UnoRuntime.queryInterface( XControlContainer.class, m_xDialog ); |
| 65 |
XTopWindow xTopWindow = UnoRuntime.queryInterface( XTopWindow.class, m_xDialog ); |
| 66 |
if ( xTopWindow != null ) |
| 67 |
xTopWindow.addTopWindowListener( this ); |
| 68 |
} |
| 69 |
catch (com.sun.star.uno.Exception ex) |
| 70 |
{ |
| 71 |
ex.printStackTrace(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
public synchronized void ThreadStop( boolean bSelf ) |
| 76 |
{ |
| 77 |
if ( bSelf || m_aThread != null && !m_bThreadFinished ) |
| 78 |
{ |
| 79 |
try |
| 80 |
{ |
| 81 |
Helper.AllowConnection( bSelf ); |
| 82 |
} |
| 83 |
catch( Exception ex ) |
| 84 |
{ |
| 85 |
ex.printStackTrace(); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
m_aThread = null; |
| 90 |
m_bThreadFinished = true; |
| 91 |
} |
| 92 |
|
| 93 |
protected void setMethods (String [] Methods) |
| 94 |
{ |
| 95 |
this.m_aMethods = Methods; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
public boolean show( ) |
| 100 |
{ |
| 101 |
m_bThreadFinished = false; |
| 102 |
|
| 103 |
if( m_xDialog != null ) m_xDialog.execute(); |
| 104 |
return m_bAction; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
public String[] getSupportedMethodNames() |
| 109 |
{ |
| 110 |
return m_aMethods; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName ) |
| 115 |
{ |
| 116 |
return true; |
| 117 |
} |
| 118 |
|
| 119 |
public void SetTitle( String sTitle ) |
| 120 |
throws Exception |
| 121 |
{ |
| 122 |
SetTitle( m_xDialog, sTitle ); |
| 123 |
} |
| 124 |
|
| 125 |
private static void SetTitle( XDialog xDialog, String sTitle ) |
| 126 |
throws Exception |
| 127 |
{ |
| 128 |
if ( xDialog == null || sTitle == null ) { |
| 129 |
return; |
| 130 |
} |
| 131 |
XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, xDialog ); |
| 132 |
if ( xDialogControl != null ) |
| 133 |
{ |
| 134 |
XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xDialogControl.getModel() ); |
| 135 |
if ( xPropSet != null ) |
| 136 |
xPropSet.setPropertyValue( "Title", sTitle ); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
protected XPropertySet GetPropSet(String sControl) |
| 141 |
{ |
| 142 |
return GetPropSet( m_xControlContainer, sControl ); |
| 143 |
} |
| 144 |
|
| 145 |
private static XPropertySet GetPropSet( XControlContainer xControlContainer, String sControl ) |
| 146 |
{ |
| 147 |
XPropertySet xPS = null; |
| 148 |
|
| 149 |
if ( xControlContainer != null && sControl != null ) |
| 150 |
{ |
| 151 |
XControl xControl = xControlContainer.getControl(sControl); |
| 152 |
xPS = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel() ); |
| 153 |
} |
| 154 |
|
| 155 |
if ( xPS == null ) |
| 156 |
throw new com.sun.star.uno.RuntimeException(); |
| 157 |
|
| 158 |
return xPS; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
protected void InsertThrobber( int X, int Y, int Width, int Height ) |
| 164 |
{ |
| 165 |
try |
| 166 |
{ |
| 167 |
XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, m_xDialog ); |
| 168 |
XControlModel xDialogModel = null; |
| 169 |
if ( xDialogControl != null ) |
| 170 |
xDialogModel = xDialogControl.getModel(); |
| 171 |
|
| 172 |
XMultiServiceFactory xDialogFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, xDialogModel ); |
| 173 |
if ( xDialogFactory != null ) |
| 174 |
{ |
| 175 |
XControlModel xThrobberModel = UnoRuntime.queryInterface( XControlModel.class, xDialogFactory.createInstance( "com.sun.star.awt.SpinningProgressControlModel" ) ); |
| 176 |
XPropertySet xThrobberProps = UnoRuntime.queryInterface( XPropertySet.class, xThrobberModel ); |
| 177 |
if ( xThrobberProps != null ) |
| 178 |
{ |
| 179 |
xThrobberProps.setPropertyValue( "Name", "WikiThrobber" ); |
| 180 |
xThrobberProps.setPropertyValue( "PositionX", Integer.valueOf( X ) ); |
| 181 |
xThrobberProps.setPropertyValue( "PositionY", Integer.valueOf( Y ) ); |
| 182 |
xThrobberProps.setPropertyValue( "Width", Integer.valueOf( Width ) ); |
| 183 |
xThrobberProps.setPropertyValue( "Height", Integer.valueOf( Height ) ); |
| 184 |
|
| 185 |
XNameContainer xDialogContainer = UnoRuntime.queryInterface( XNameContainer.class, xDialogModel ); |
| 186 |
xDialogContainer.insertByName( "WikiThrobber", xThrobberModel ); |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
catch( Exception e ) |
| 191 |
{ |
| 192 |
e.printStackTrace(); |
| 193 |
} |
| 194 |
|
| 195 |
SetThrobberVisible( false ); |
| 196 |
} |
| 197 |
|
| 198 |
public void SetThrobberActive( boolean bActive ) |
| 199 |
{ |
| 200 |
if ( m_xControlContainer != null ) |
| 201 |
{ |
| 202 |
try |
| 203 |
{ |
| 204 |
XAnimation xThrobber = UnoRuntime.queryInterface( XAnimation.class, m_xControlContainer.getControl( "WikiThrobber" ) ); |
| 205 |
if ( xThrobber != null ) |
| 206 |
{ |
| 207 |
if ( bActive ) |
| 208 |
xThrobber.startAnimation(); |
| 209 |
else |
| 210 |
xThrobber.stopAnimation(); |
| 211 |
} |
| 212 |
} |
| 213 |
catch( Exception e ) |
| 214 |
{ |
| 215 |
e.printStackTrace(); |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
public void SetThrobberVisible( boolean bVisible ) |
| 221 |
{ |
| 222 |
if ( m_xControlContainer != null ) |
| 223 |
{ |
| 224 |
try |
| 225 |
{ |
| 226 |
XWindow xWindow = UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( "WikiThrobber" ) ); |
| 227 |
if ( xWindow != null ) |
| 228 |
xWindow.setVisible( bVisible ); |
| 229 |
} |
| 230 |
catch ( Exception e ) |
| 231 |
{ |
| 232 |
e.printStackTrace(); |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
public void SetFocusTo( String aControl ) |
| 238 |
{ |
| 239 |
if ( m_xControlContainer != null ) |
| 240 |
{ |
| 241 |
try |
| 242 |
{ |
| 243 |
XWindow xWindow = UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( aControl ) ); |
| 244 |
if ( xWindow != null ) |
| 245 |
xWindow.setFocus(); |
| 246 |
} |
| 247 |
catch ( Exception e ) |
| 248 |
{ |
| 249 |
e.printStackTrace(); |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
public void DisposeDialog() |
| 255 |
{ |
| 256 |
Helper.Dispose( m_xDialog ); |
| 257 |
} |
| 258 |
|
| 259 |
public void windowOpened( EventObject e ) |
| 260 |
{} |
| 261 |
|
| 262 |
public void windowClosing( EventObject e ) |
| 263 |
{} |
| 264 |
|
| 265 |
public void windowClosed( EventObject e ) |
| 266 |
{} |
| 267 |
|
| 268 |
public void windowMinimized( EventObject e ) |
| 269 |
{} |
| 270 |
|
| 271 |
public void windowNormalized( EventObject e ) |
| 272 |
{} |
| 273 |
|
| 274 |
public void windowActivated( EventObject e ) |
| 275 |
{} |
| 276 |
|
| 277 |
public void windowDeactivated( EventObject e ) |
| 278 |
{} |
| 279 |
|
| 280 |
public void disposing( EventObject e ) |
| 281 |
{} |
| 282 |
} |
| 283 |
|