| 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.script.framework.provider; |
| 20 |
|
| 21 |
import com.sun.star.beans.NamedValue; |
| 22 |
import com.sun.star.configuration.theDefaultProvider; |
| 23 |
import com.sun.star.container.XNameAccess; |
| 24 |
import com.sun.star.lang.XMultiServiceFactory; |
| 25 |
import com.sun.star.script.framework.container.ScriptMetaData; |
| 26 |
import com.sun.star.script.provider.XScriptContext; |
| 27 |
import com.sun.star.uno.AnyConverter; |
| 28 |
import com.sun.star.uno.UnoRuntime; |
| 29 |
|
| 30 |
import javax.swing.JOptionPane; |
| 31 |
import javax.swing.JDialog; |
| 32 |
|
| 33 |
public abstract class ScriptEditorBase implements ScriptEditor { |
| 34 |
protected XScriptContext context; |
| 35 |
|
| 36 |
public void setContext(XScriptContext context) { |
| 37 |
this.context = context; |
| 38 |
} |
| 39 |
|
| 40 |
public boolean isMacroExecutionEnabled() { |
| 41 |
XNameAccess xNameAccess = null; |
| 42 |
try { |
| 43 |
String sAccess = "com.sun.star.configuration.ConfigurationAccess"; |
| 44 |
XMultiServiceFactory xMSFCfg = theDefaultProvider.get(context.getComponentContext()); |
| 45 |
Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, |
| 46 |
new Object[] { new NamedValue("nodepath", "org.openoffice.Office.Common/Security/Scripting") }); |
| 47 |
xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oAccess); |
| 48 |
Object result = xNameAccess.getByName("DisableMacrosExecution"); |
| 49 |
boolean bMacrosDisabled = AnyConverter.toBoolean(result); |
| 50 |
if (bMacrosDisabled) |
| 51 |
return false; |
| 52 |
} catch (com.sun.star.uno.Exception e) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
return true; |
| 56 |
} |
| 57 |
|
| 58 |
// Wraps long error messages |
| 59 |
private static class NarrowOptionPane extends JOptionPane { |
| 60 |
private static final long serialVersionUID = 1L; |
| 61 |
public int getMaxCharactersPerLineCount() { |
| 62 |
return 100; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
public void showErrorMessage(String message) { |
| 67 |
JOptionPane optionPane = new NarrowOptionPane(); |
| 68 |
optionPane.setMessage(message); |
| 69 |
optionPane.setMessageType(JOptionPane.ERROR_MESSAGE); |
| 70 |
JDialog dialog = optionPane.createDialog(null, "Error"); |
| 71 |
dialog.setVisible(true); |
| 72 |
} |
| 73 |
} |