cid#1607171 Data race condition
[LibreOffice.git] / swext / mediawiki / src / com / sun / star / wiki / WikiDialog.java
blob66bef678e4e159d12a0101532d5bb5e1a973051f
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package com.sun.star.wiki;
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;
39 public class WikiDialog implements XDialogEventHandler, XTopWindowListener
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;
51 /** Creates a new instance of WikiDialog */
52 public WikiDialog(XComponentContext c, String DialogURL)
54 this.m_xContext = c;
55 XMultiComponentFactory xMCF = m_xContext.getServiceManager();
56 m_aSettings = Settings.getSettings(m_xContext);
57 try
59 Object obj;
60 obj = xMCF.createInstanceWithContext("com.sun.star.awt.DialogProvider2", m_xContext );
61 XDialogProvider2 xDialogProvider = UnoRuntime.queryInterface( XDialogProvider2.class, obj );
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 );
69 catch (com.sun.star.uno.Exception ex)
71 ex.printStackTrace();
75 public synchronized void ThreadStop( boolean bSelf )
77 if ( bSelf || m_aThread != null && !m_bThreadFinished )
79 try
81 Helper.AllowConnection( bSelf );
83 catch( Exception ex )
85 ex.printStackTrace();
89 m_aThread = null;
90 m_bThreadFinished = true;
93 protected void setMethods (String [] Methods)
95 this.m_aMethods = Methods;
99 public boolean show( )
101 m_bThreadFinished = false;
103 if( m_xDialog != null ) m_xDialog.execute();
104 return m_bAction;
108 public String[] getSupportedMethodNames()
110 return m_aMethods;
114 public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )
116 return true;
119 public void SetTitle( String sTitle )
120 throws Exception
122 SetTitle( m_xDialog, sTitle );
125 private static void SetTitle( XDialog xDialog, String sTitle )
126 throws Exception
128 if ( xDialog == null || sTitle == null ) {
129 return;
131 XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, xDialog );
132 if ( xDialogControl != null )
134 XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xDialogControl.getModel() );
135 if ( xPropSet != null )
136 xPropSet.setPropertyValue( "Title", sTitle );
140 protected XPropertySet GetPropSet(String sControl)
142 return GetPropSet( m_xControlContainer, sControl );
145 private static XPropertySet GetPropSet( XControlContainer xControlContainer, String sControl )
147 XPropertySet xPS = null;
149 if ( xControlContainer != null && sControl != null )
151 XControl xControl = xControlContainer.getControl(sControl);
152 xPS = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel() );
155 if ( xPS == null )
156 throw new com.sun.star.uno.RuntimeException();
158 return xPS;
163 protected void InsertThrobber( int X, int Y, int Width, int Height )
167 XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, m_xDialog );
168 XControlModel xDialogModel = null;
169 if ( xDialogControl != null )
170 xDialogModel = xDialogControl.getModel();
172 XMultiServiceFactory xDialogFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, xDialogModel );
173 if ( xDialogFactory != null )
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 )
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 ) );
185 XNameContainer xDialogContainer = UnoRuntime.queryInterface( XNameContainer.class, xDialogModel );
186 xDialogContainer.insertByName( "WikiThrobber", xThrobberModel );
190 catch( Exception e )
192 e.printStackTrace();
195 SetThrobberVisible( false );
198 public void SetThrobberActive( boolean bActive )
200 if ( m_xControlContainer != null )
204 XAnimation xThrobber = UnoRuntime.queryInterface( XAnimation.class, m_xControlContainer.getControl( "WikiThrobber" ) );
205 if ( xThrobber != null )
207 if ( bActive )
208 xThrobber.startAnimation();
209 else
210 xThrobber.stopAnimation();
213 catch( Exception e )
215 e.printStackTrace();
220 public void SetThrobberVisible( boolean bVisible )
222 if ( m_xControlContainer != null )
226 XWindow xWindow = UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( "WikiThrobber" ) );
227 if ( xWindow != null )
228 xWindow.setVisible( bVisible );
230 catch ( Exception e )
232 e.printStackTrace();
237 public void SetFocusTo( String aControl )
239 if ( m_xControlContainer != null )
243 XWindow xWindow = UnoRuntime.queryInterface( XWindow.class, m_xControlContainer.getControl( aControl ) );
244 if ( xWindow != null )
245 xWindow.setFocus();
247 catch ( Exception e )
249 e.printStackTrace();
254 public void DisposeDialog()
256 Helper.Dispose( m_xDialog );
259 public void windowOpened( EventObject e )
262 public void windowClosing( EventObject e )
265 public void windowClosed( EventObject e )
268 public void windowMinimized( EventObject e )
271 public void windowNormalized( EventObject e )
274 public void windowActivated( EventObject e )
277 public void windowDeactivated( EventObject e )
280 public void disposing( EventObject e )