diff options
author | Jan Holesovsky <kendy@suse.cz> | 2011-03-23 16:59:26 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2011-03-23 16:59:26 +0100 |
commit | 3b7ab82aee60aec1e47c1e253d3977a3fc011f5b (patch) | |
tree | 1ebee7adb28ba3175deee3948aee8f5489d9b509 /scripting | |
parent | Remove DECLARE_LIST( FmCtrlModelList, XInterface* ). (diff) | |
parent | CWS-TOOLING: integrate CWS vcl120 (diff) | |
download | core-3b7ab82aee60aec1e47c1e253d3977a3fc011f5b.tar.gz core-3b7ab82aee60aec1e47c1e253d3977a3fc011f5b.zip |
Merge commit 'ooo/DEV300_m103'
Conflicts:
basic/source/runtime/makefile.mk
basic/source/runtime/step2.cxx
desktop/prj/build.lst
desktop/source/app/app.cxx
desktop/source/deployment/registry/dp_backend.cxx
drawinglayer/source/attribute/fontattribute.cxx
editeng/inc/editeng/fontitem.hxx
editeng/source/editeng/edtspell.cxx
editeng/source/misc/svxacorr.cxx
framework/inc/services/substitutepathvars.hxx
framework/source/services/substitutepathvars.cxx
sfx2/qa/cppunit/makefile.mk
sfx2/source/doc/SfxDocumentMetaData.cxx
sfx2/source/doc/objxtor.cxx
svx/source/dialog/svxruler.cxx
sysui/desktop/icons/so9_base_app.ico
sysui/desktop/icons/so9_calc_app.ico
sysui/desktop/icons/so9_draw_app.ico
sysui/desktop/icons/so9_impress_app.ico
sysui/desktop/icons/so9_main_app.ico
sysui/desktop/icons/so9_math_app.ico
sysui/desktop/icons/so9_writer_app.ico
xmlhelp/source/cxxhelp/provider/databases.cxx
xmlhelp/source/cxxhelp/provider/db.cxx
xmlhelp/source/cxxhelp/provider/db.hxx
Diffstat (limited to 'scripting')
3 files changed, 94 insertions, 71 deletions
diff --git a/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java new file mode 100644 index 000000000000..fffb78523798 --- /dev/null +++ b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java @@ -0,0 +1,44 @@ +/************************************************************************* +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2011 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +package com.sun.star.script.framework.provider; + +import javax.swing.SwingUtilities; + +// On Mac OS X, AWT/Swing must not be accessed from the AppKit thread, so call +// SwingUtilities.invokeLater always on a fresh thread to avoid that problem +// (also, the current thread must not wait for that fresh thread to terminate, +// as that would cause a deadlock if this thread is the AppKit thread): +public final class SwingInvocation { + public static void invoke(final Runnable doRun) { + new Thread("SwingInvocation") { + public void run() { SwingUtilities.invokeLater(doRun); } + }.start(); + } + + private SwingInvocation() {} +} diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java index ece0d0bdd8b6..cbbcfc34f78f 100755 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java @@ -47,6 +47,7 @@ import java.util.HashMap; import com.sun.star.script.provider.XScriptContext; import com.sun.star.script.framework.provider.ScriptEditor; +import com.sun.star.script.framework.provider.SwingInvocation; import com.sun.star.script.framework.container.ScriptMetaData; import com.sun.star.script.framework.provider.ClassLoaderFactory; @@ -128,7 +129,9 @@ public class ScriptEditorForBeanShell */ public static ScriptEditorForBeanShell getEditor(URL url) { - return (ScriptEditorForBeanShell)BEING_EDITED.get(url); + synchronized (BEING_EDITED) { + return (ScriptEditorForBeanShell)BEING_EDITED.get(url); + } } /** @@ -194,8 +197,7 @@ public class ScriptEditorForBeanShell * @param context The context in which to execute the script * */ - public void edit(XScriptContext context, ScriptMetaData entry) { - + public void edit(final XScriptContext context, ScriptMetaData entry) { if (entry != null ) { try { ClassLoader cl = null; @@ -205,26 +207,30 @@ public class ScriptEditorForBeanShell catch (Exception ignore) // TODO re-examine error handling { } + final ClassLoader theCl = cl; String sUrl = entry.getParcelLocation(); if ( !sUrl.endsWith( "/" ) ) { sUrl += "/"; } sUrl += entry.getLanguageName(); - URL url = entry.getSourceURL(); - - // check if there is already an editing session for this script - if (BEING_EDITED.containsKey(url)) - { - ScriptEditorForBeanShell editor = - (ScriptEditorForBeanShell) BEING_EDITED.get(url); - - editor.frame.toFront(); - } - else - { - new ScriptEditorForBeanShell(context, cl, url); - } + final URL url = entry.getSourceURL(); + SwingInvocation.invoke( + new Runnable() { + public void run() { + ScriptEditorForBeanShell editor; + synchronized (BEING_EDITED) { + editor = (ScriptEditorForBeanShell) + BEING_EDITED.get(url); + if (editor == null) { + editor = new ScriptEditorForBeanShell( + context, theCl, url); + BEING_EDITED.put(url, editor); + } + } + editor.frame.toFront(); + } + }); } catch (IOException ioe) { showErrorMessage( "Error loading file: " + ioe.getMessage() ); @@ -269,8 +275,6 @@ public class ScriptEditorForBeanShell this.model.setView(this.view); initUI(); frame.show(); - - BEING_EDITED.put(url, this); } private void showErrorMessage(String message) { @@ -384,7 +388,7 @@ public class ScriptEditorForBeanShell private void shutdown() { - if (BEING_EDITED.containsKey(scriptURL)) { + synchronized (BEING_EDITED) { BEING_EDITED.remove(scriptURL); } } diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java index 4adbbc3a10d3..e7f08c628420 100755 --- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java +++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java @@ -36,6 +36,7 @@ import org.mozilla.javascript.tools.debugger.ScopeProvider; import com.sun.star.script.provider.XScriptContext; import com.sun.star.script.framework.container.ScriptMetaData; import com.sun.star.script.framework.provider.ScriptEditor; +import com.sun.star.script.framework.provider.SwingInvocation; import com.sun.star.script.framework.log.LogUtils; import java.io.InputStream; @@ -45,7 +46,6 @@ import java.net.URL; import java.util.Map; import java.util.HashMap; -import javax.swing.SwingUtilities; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -117,7 +117,9 @@ public class ScriptEditorForJavaScript implements ScriptEditor */ public static ScriptEditorForJavaScript getEditor(URL url) { - return (ScriptEditorForJavaScript)BEING_EDITED.get(url); + synchronized (BEING_EDITED) { + return (ScriptEditorForJavaScript)BEING_EDITED.get(url); + } } /** @@ -187,31 +189,25 @@ public class ScriptEditorForJavaScript implements ScriptEditor sUrl += "/"; } sUrl += entry.getLanguageName(); - URL url = entry.getSourceURL(); - - // check if there is already an editing session for this script - //if (BEING_EDITED.containsKey(url)) - if ( rhinoWindow != null ) - { - ScriptEditorForJavaScript editor = - (ScriptEditorForJavaScript) BEING_EDITED.get(url); - if ( editor == null ) - { - editor = new ScriptEditorForJavaScript( context, url ); - editor.edit( context, entry ); - } - else - { - rhinoWindow.showScriptWindow( url ); - } - } - else - { - ScriptEditorForJavaScript editor = - new ScriptEditorForJavaScript( context, url ); - - } - rhinoWindow.toFront(); + final URL url = entry.getSourceURL(); + SwingInvocation.invoke( + new Runnable() { + public void run() { + synchronized (BEING_EDITED) { + ScriptEditorForJavaScript editor = + (ScriptEditorForJavaScript) BEING_EDITED.get( + url); + if (editor == null) { + editor = new ScriptEditorForJavaScript( + context, url); + BEING_EDITED.put(url, editor); + } + } + assert rhinoWindow != null; + rhinoWindow.showScriptWindow(url); + rhinoWindow.toFront(); + } + }); } catch ( IOException e ) { @@ -234,11 +230,6 @@ public class ScriptEditorForJavaScript implements ScriptEditor this.scriptURL = url; - synchronized( ScriptEditorForJavaScript.class ) - { - BEING_EDITED.put(url, this); - } - } /** @@ -274,13 +265,9 @@ public class ScriptEditorForJavaScript implements ScriptEditor } final Main sdb = new Main("Rhino JavaScript Debugger"); - swingInvoke(new Runnable() { - public void run() { - sdb.pack(); - sdb.setSize(640, 640); - sdb.setVisible(true); - } - }); + sdb.pack(); + sdb.setSize(640, 640); + sdb.setVisible(true); sdb.setExitAction(new Runnable() { public void run() { sdb.clearAllBreakpoints(); @@ -306,18 +293,6 @@ public class ScriptEditorForJavaScript implements ScriptEditor } } - private static void swingInvoke(Runnable f) { - if (SwingUtilities.isEventDispatchThread()) { - f.run(); - return; - } - try { - SwingUtilities.invokeAndWait(f); - } catch (Exception exc) { - LogUtils.DEBUG( LogUtils.getTrace( exc ) ); - } - } - private void shutdown() { // dereference Rhino Debugger window |