Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2994

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/94/2994/1

Init: Added new file AbstractErrorHandler.py

Change-Id: I8d5a304a51af734379c5597e9cdddf6ecfa6ba8a
---
A wizards/com/sun/star/wizards/web/AbstractErrorHandler.py
1 file changed, 181 insertions(+), 0 deletions(-)



diff --git a/wizards/com/sun/star/wizards/web/AbstractErrorHandler.py 
b/wizards/com/sun/star/wizards/web/AbstractErrorHandler.py
new file mode 100644
index 0000000..5f79384
--- /dev/null
+++ b/wizards/com/sun/star/wizards/web/AbstractErrorHandler.py
@@ -0,0 +1,181 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+#   Licensed to the Apache Software Foundation (ASF) under one or more
+#   contributor license agreements. See the NOTICE file distributed
+#   with this work for additional information regarding copyright
+#   ownership. The ASF licenses this file to you under the Apache
+#   License, Version 2.0 (the "License"); you may not use this file
+#   except in compliance with the License. You may obtain a copy of
+#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+from abc import abstractmethod
+
+from .ErrorHandler import ErrorHandler
+from ..common.SystemDialog import SystemDialog
+
+from com.sun.star.awt.VclWindowPeerAttribute import OK, DEF_OK, OK_CANCEL, DEF_CANCEL
+from com.sun.star.awt.VclWindowPeerAttribute import YES_NO, DEF_NO, DEF_YES
+
+#import com.sun.star.awt.VclWindowPeerAttribute
+
+
+# An abstract implementation of ErrorHandler, which
+# uses a renderer method geMessageFor(Exception, Object, int, int)
+# (in this class still abstract...)
+# to render the errors, and displays
+# error messeges.
+class AbstractErrorHandler(ErrorHandler):
+
+    xmsf = None
+    peer = None
+
+    def __init__(self, xmsf, peer_):
+        self.xmsf = xmsf
+        self.peer = peer_
+
+    # Implementation of ErrorHandler:
+    # shows a message box with the rendered error.
+    # @param arg identifies the error. This object is passed to the render method
+    # which returns the right error message.
+    # @return true/false for continue/abort.
+    def error(self, ex, arg, ix, errorType):
+        if (errorType == ErrorHandler.ERROR_FATAL):
+                return not self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_PROCESS_FATAL):
+                return not self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_NORMAL_ABORT):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_NORMAL_IGNORE):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_QUESTION_CANCEL):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_QUESTION_OK):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_QUESTION_NO):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_QUESTION_YES):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_WARNING):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        elif (errorType == ErrorHandler.ERROR_MESSAGE):
+                return self.showMessage(self.getMessageFor(ex, arg, ix, errorType), errorType)
+        raise IllegalArgumentException("unknown error type")
+
+    # @deprecated
+    # @param message
+    # @param errorType
+    # @return true if the ok/yes button is clicked, false otherwise.
+    def showMessage(self, message, errorType):
+        return self.showMessage1(self.xmsf, self.peer, message, errorType)
+
+    # display a message
+    # @deprecated
+    # @param xmsf
+    # @param message the message to display
+    # @param errorType an int constant from the ErrorHandler interface.
+    # @return
+    @classmethod
+    def showMessage1(self, xmsf, peer, message, errorType):
+        serviceName = self.getServiceNameFor(errorType)
+        attribute = self.getAttributeFor(errorType)
+        b = SystemDialog.showMessageBox(xmsf, serviceName, attribute, message, peer)
+        return b == self.getTrueFor(errorType)
+
+    @classmethod
+    def showMessage2(self, xmsf, peer, message, dialogType, buttons, defaultButton, returnTrueOn):
+        b = SystemDialog.showMessageBox(xmsf, dialogType, defaultButton + buttons, message, peer, )
+        return b == returnTrueOn
+
+
+    # normally ok(1) is the value for true.
+    # but a question dialog may use yes. so i use this method
+    # for each error type to get its type of "true" value.
+    # @param errorType
+    # @return
+    @classmethod
+    def getTrueFor(self, errorType):
+        if (errorType in (ErrorHandler.ERROR_FATAL, ErrorHandler.ERROR_PROCESS_FATAL,
+                          ErrorHandler.ERROR_NORMAL_ABORT, ErrorHandler.ERROR_NORMAL_IGNORE,
+                          ErrorHandler.ERROR_QUESTION_CANCEL, ErrorHandler.ERROR_QUESTION_OK)):
+                return 1
+        elif (errorType in (ErrorHandler.ERROR_QUESTION_NO, ErrorHandler.ERROR_QUESTION_YES)):
+                return 2
+        elif (errorType in (ErrorHandler.ERROR_WARNING, ErrorHandler.ERROR_MESSAGE)):
+                return 1
+        raise IllegalArgumentException("unkonown error type")
+
+
+    # @param errorType
+    # @return the Uno attributes for each error type.
+    @classmethod
+    def getAttributeFor(self, errorType):
+        if (errorType == ErrorHandler.ERROR_FATAL):
+                return OK
+        elif (errorType == ErrorHandler.ERROR_PROCESS_FATAL):
+                return OK
+        elif (errorType == ErrorHandler.ERROR_NORMAL_ABORT):
+                return OK_CANCEL + DEF_CANCEL
+        elif (errorType == ErrorHandler.ERROR_NORMAL_IGNORE):
+                return OK_CANCEL + DEF_OK
+        elif (errorType == ErrorHandler.ERROR_QUESTION_CANCEL):
+                return OK_CANCEL + DEF_CANCEL
+        elif (errorType == ErrorHandler.ERROR_QUESTION_OK):
+                return OK_CANCEL + DEF_OK
+        elif (errorType == ErrorHandler.ERROR_QUESTION_NO):
+                return YES_NO + DEF_NO
+        elif (errorType == ErrorHandler.ERROR_QUESTION_YES):
+                return YES_NO + DEF_YES
+        elif (errorType == ErrorHandler.ERROR_WARNING):
+                return OK
+        elif (errorType == ErrorHandler.ERROR_MESSAGE):
+                return OK
+        raise IllegalArgumentException("unkonown error type")
+
+    # @deprecated
+    # @param errorType
+    # @return the uno service name for each error type
+    @classmethod
+    def getServiceNameFor(self, errorType):
+        if (errorType == ErrorHandler.ERROR_FATAL):
+                return "errorbox"
+        elif (errorType == ErrorHandler.ERROR_PROCESS_FATAL):
+                return "errorbox"
+        elif (errorType == ErrorHandler.ERROR_NORMAL_ABORT):
+                return "errorbox"
+        elif (errorType == ErrorHandler.ERROR_NORMAL_IGNORE):
+                return "warningbox"
+        elif (errorType == ErrorHandler.ERROR_QUESTION_CANCEL):
+                return "querybox"
+        elif (errorType == ErrorHandler.ERROR_QUESTION_OK):
+                return "querybox"
+        elif (errorType == ErrorHandler.ERROR_QUESTION_NO):
+                return "querybox"
+        elif (errorType == ErrorHandler.ERROR_QUESTION_YES):
+                return "querybox"
+        elif (errorType == ErrorHandler.ERROR_WARNING):
+                return "warningbox"
+        elif (errorType == ErrorHandler.ERROR_MESSAGE):
+                return "infobox"
+        raise IllegalArgumentException("unkonown error type")
+
+    # renders the error
+    # @param ex the exception
+    # @param arg a free argument
+    # @param ix a free argument
+    # @param type the error type (from the int constants
+    # in ErrorHandler interface)
+    # @return a Strings which will be displayed in the message box,
+    # and which describes the error, and the needed action from the user.
+    @abstractmethod
+    def getMessageFor(self, ex, arg, ix, errorType):
+        pass
+
+
+

-- 
To view, visit https://gerrit.libreoffice.org/2994
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d5a304a51af734379c5597e9cdddf6ecfa6ba8a
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Javier Fernandez <javier.fgb@gmail.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.