Bug 364950 - Workbench is not mirrored correctly when using "nl" option
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
index b48e945..5b0b895 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
@@ -77,6 +77,7 @@
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
@@ -218,10 +219,8 @@
appContext);
appModel.setContext(appContext);
- String rtlMode = getArgValue(E4Workbench.RTL_MODE, applicationContext,
- false);
- appModel.getTransientData().put(E4Workbench.RTL_MODE,
- "rtl".equals(rtlMode));
+ boolean isRtl = ((Window.getDefaultOrientation() & SWT.RIGHT_TO_LEFT) != 0);
+ appModel.getTransientData().put(E4Workbench.RTL_MODE, isRtl);
// for compatibility layer: set the application in the OSGi service
// context (see Workbench#getInstance())
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java
index ac7b457..01179ab 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -886,7 +886,30 @@
return checkCommandLineLocale(); //Use the default value if there is nothing specified
}
-
+
+ /**
+ * Check whether the workbench messages are in a Bidi language. This method
+ * will return <code>null</code> if it is unable to determine message
+ * properties.
+ */
+ private Boolean isBidiMessageText() {
+ // Check if the user installed the NLS packs for bidi
+ String message = WorkbenchMessages.Startup_Loading_Workbench;
+ if (message == null)
+ return null;
+
+ try {
+ // use qualified class name to avoid import statement
+ // and premature attempt to resolve class reference
+ boolean isBidi = com.ibm.icu.text.Bidi.requiresBidi(message.toCharArray(), 0,
+ message.length());
+ return new Boolean(isBidi);
+ } catch (NoClassDefFoundError e) {
+ // the ICU Base bundle used in place of ICU?
+ return null;
+ }
+ }
+
/**
* Check to see if the command line parameter for -nl
* has been set. If so imply the orientation from this
@@ -904,21 +927,23 @@
* @see SWT#RIGHT_TO_LEFT
*/
private int checkCommandLineLocale() {
-
- //Check if the user property is set. If not do not
- //rely on the vm.
- if(System.getProperty(NL_USER_PROPERTY) == null) {
- return SWT.NONE;
+ // Check if the user property is set. If not, do not rely on the VM.
+ if (System.getProperty(NL_USER_PROPERTY) == null) {
+ Boolean needRTL = isBidiMessageText();
+ if (needRTL != null && needRTL.booleanValue())
+ return SWT.RIGHT_TO_LEFT;
+ } else {
+ String lang = Locale.getDefault().getLanguage();
+ boolean bidiLangauage = "iw".equals(lang) || "he".equals(lang) || "ar".equals(lang) || //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "fa".equals(lang) || "ur".equals(lang); //$NON-NLS-1$ //$NON-NLS-2$
+ if (bidiLangauage) {
+ Boolean needRTL = isBidiMessageText();
+ if (needRTL == null)
+ return SWT.RIGHT_TO_LEFT;
+ if (needRTL.booleanValue())
+ return SWT.RIGHT_TO_LEFT;
+ }
}
-
- Locale locale = Locale.getDefault();
- String lang = locale.getLanguage();
-
- if ("iw".equals(lang) || "he".equals(lang) || "ar".equals(lang) || //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "fa".equals(lang) || "ur".equals(lang)) { //$NON-NLS-1$ //$NON-NLS-2$
- return SWT.RIGHT_TO_LEFT;
- }
-
return SWT.NONE;
}