Revision 1772

tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditor.java (revision 1772)
27 27

  
28 28
import java.util.ArrayList;
29 29
import java.util.List;
30
import java.util.Locale;
30 31

  
31 32
import org.eclipse.core.runtime.CoreException;
32 33
import org.eclipse.core.runtime.IConfigurationElement;
......
141 142

  
142 143
	public static final String ID = ConcordanceEditor.class.getName();
143 144

  
144
	String locale = RCPPreferences.getInstance().getString(RCPPreferences.UI_LOCALE);
145
	String locale = Locale.getDefault().getLanguage();//RCPPreferences.getInstance().getString(RCPPreferences.CONFIG_LOCALE);
145 146

  
146

  
147 147
	private static final String BACKTOTEXT_COMMAND_ID = "org.txm.rcp.extensionpoint.backtotext"; //$NON-NLS-1$
148 148

  
149 149
	/** The lineids. */
tmp/org.txm.rcp/src/main/java/org/txm/rcp/utils/LanguageSwitchHandler.java (revision 1772)
37 37
import java.net.MalformedURLException;
38 38
import java.net.URL;
39 39
import java.util.ArrayList;
40
import java.util.Locale;
40 41

  
41 42
import org.eclipse.core.commands.AbstractHandler;
42 43
import org.eclipse.core.commands.ExecutionEvent;
43 44
import org.eclipse.core.commands.ExecutionException;
44 45
import org.eclipse.core.runtime.Platform;
45
import org.eclipse.core.runtime.preferences.IPreferencesService;
46 46
import org.eclipse.jface.window.Window;
47 47
import org.eclipse.osgi.service.datalocation.Location;
48 48
import org.eclipse.osgi.util.NLS;
49 49
import org.eclipse.swt.widgets.Shell;
50 50
import org.eclipse.ui.PlatformUI;
51 51
import org.eclipse.ui.handlers.HandlerUtil;
52
import org.txm.core.preferences.TXMPreferences;
53
import org.txm.rcp.Application;
54
import org.txm.rcp.TxmPreferences;
55 52
import org.txm.rcp.messages.TXMUIMessages;
56
import org.txm.rcp.preferences.RCPPreferences;
57 53
import org.txm.rcp.swt.dialog.ComboDialog;
54
import org.txm.utils.io.IOUtils;
58 55
import org.txm.utils.logger.Log;
59 56
import org.txm.utils.logger.MessageBox;
60
// TODO: Auto-generated Javadoc
57

  
61 58
/**
62 59
 * Switches the language in RCP based products. Works only if the product is
63 60
 * deployed to the local file system since the <product>.ini file is altered.
......
66 63
 * @see org.eclipse.core.commands.AbstractHandler
67 64
 */
68 65
public class LanguageSwitchHandler extends AbstractHandler {
66
	
69 67
	/**
70 68
	 * The constructor.
71 69
	 */
......
83 81
	@Override
84 82
	public Object execute(ExecutionEvent event) throws ExecutionException {
85 83

  
86
		IPreferencesService service = Platform.getPreferencesService();
87
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
88
				.getShell();
84
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
85
		
86
		String locale = Locale.getDefault().getLanguage();//RCPPreferences.getInstance().getString(RCPPreferences.UI_LOCALE);
87
		
89 88
		ArrayList<String> values = new ArrayList<String>();
90 89
		values.add("fr"); //$NON-NLS-1$
91 90
		values.add("en"); //$NON-NLS-1$
92 91
		values.add("ru"); //$NON-NLS-1$
93
		ComboDialog d = new ComboDialog(shell, TXMUIMessages.chooseTheLanguage, values,
94
				service.getString(Application.PLUGIN_ID,
95
						RCPPreferences.UI_LOCALE, "fr", null)); //$NON-NLS-1$
92
		
93
		if (!values.contains(locale)) { // set selected locale
94
			locale = "en";
95
		}
96
		
97
		ComboDialog d = new ComboDialog(shell, TXMUIMessages.chooseTheLanguage, values, locale); //$NON-NLS-1$
96 98
		if (d.open() == Window.OK) {
97
			RCPPreferences.getInstance().put(RCPPreferences.UI_LOCALE, d.getSelectedValue());
98
		} else
99
			locale = d.getSelectedValue();
100
			//RCPPreferences.getInstance().put(RCPPreferences.CONFIG_LOCALE, locale);
101
		} else {
99 102
			return null;
100

  
101
		String locale = service.getString(Application.PLUGIN_ID,
102
				RCPPreferences.UI_LOCALE, "fr", null); //$NON-NLS-1$
103
		if (locale.length() == 0)
104
			Log.warning(TXMUIMessages.interfaceLanguageLOCALEWasNotSet);
103
		}
104
		
105 105
		// Does not work:
106
		//System.getProperties().setProperty("eclipse.exitdata", "-nl " + locale);
107
		//changeLocaleTXMIni(locale);
108
		changeLocaleConfigIni(locale);
109
		PlatformUI.getWorkbench().restart();
110

  
106
		//	System.getProperties().setProperty(IApplicationContext.EXIT_DATA_PROPERTY, "-nl " + locale);
107
		//	changeLocaleTXMIni(locale);
108
		
109
		if (changeLocaleConfigIni(locale)) {
110
			PlatformUI.getWorkbench().restart();
111
		} else {
112
			Log.warning("** Error: TXM language configuration could not be set. You can set TXM language by editing HOME/TXM-<version>/.txm/TXM.ini) configuration file by adding '-nl\n<language code>' before the '-vmargs' line.");
113
		}
114
		
111 115
		return null;
112 116
	}
113 117

  
......
220 224
	 *
221 225
	 * @param locale the locale
222 226
	 */
223
	public static void changeLocaleConfigIni(String locale) {
224

  
227
	public static boolean changeLocaleConfigIni(String locale) {
228
		
225 229
		Location configArea = Platform.getConfigurationLocation();
226 230
		
227 231
		if (configArea == null) {
228
			return;
232
			return false;
229 233
		}
230 234

  
231 235
		String fileName = Platform.getConfigurationLocation().getURL().getFile() + 
......
234 238
		File file = new File(fileName);
235 239
		if (!file.exists()) {
236 240
			MessageBox.error(NLS.bind(TXMUIMessages.theFileP0DoesNotExist, file.getAbsolutePath()));
237
			return;
241
			return false;
238 242
		}
239 243
		String fileNameBackup = fileName + ".bak"; //$NON-NLS-1$
240 244
		file.renameTo(new File(fileNameBackup));
241 245
		
242 246
		// update config.ini
243
		System.out.println("config.ini"+fileName); //$NON-NLS-1$
244
		Log.severe("config.ini"+fileName); //$NON-NLS-1$
247
		Log.info("config.ini: "+fileName); //$NON-NLS-1$
245 248
		try {
246 249

  
247 250
			BufferedReader in = new BufferedReader(new FileReader(fileNameBackup));
......
290 293
		} catch (IOException e) {
291 294
			org.txm.utils.logger.Log.printStackTrace(e);
292 295
		}
296
		
297
		String txt;
298
		try {
299
			txt = IOUtils.getText(file, "UTF-8");
300
			return txt.contains("osgi.nl="+locale);
301
		} catch (IOException e) {
302
			e.printStackTrace();
303
			return false;
304
		}
293 305
	}
294 306
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/preferences/LocalePreferencePage.java (revision 1772)
64 64
	@Override
65 65
	protected void createFieldEditors() {
66 66
		String[][] values = { { "fran├žais", "fr" }, { "english", "en" } }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
67
		locale = new RadioGroupFieldEditor(RCPPreferences.UI_LOCALE,
67
		locale = new RadioGroupFieldEditor(RCPPreferences.CONFIG_LOCALE,
68 68
				TXMUIMessages.userInterfaceLanguage, 1, values,
69 69
				getFieldEditorParent());
70 70
		addField(locale);
tmp/org.txm.rcp/src/main/java/org/txm/rcp/preferences/RCPPreferences.java (revision 1772)
17 17
//	public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(RCPPreferences.class).getSymbolicName();
18 18

  
19 19

  
20
	/** The Constant UI_LOCALE. */
21
	public static final String UI_LOCALE = "ui_locale"; //$NON-NLS-1$
22

  
20
	/** Preference set with the osgi-nl parameter */
21
	public static final String CONFIG_LOCALE = "ui_locale"; //$NON-NLS-1$
22
	/** Preference set with the -Xms parameter */
23
	public static final String CONFIG_XMS = "config_xms"; //$NON-NLS-1$
24
	/** Preference set with the osgi-nl parameter */
25
	public static final String CONFIG_XMX = "config_xmx"; //$NON-NLS-1$
26
	
23 27
	/** The Constant USER_ALERT_DELETE. */
24 28
	public static final String USER_ALERT_DELETE = "user_alert_delete"; //$NON-NLS-1$
25 29

  
......
69 73
		preferences.put(TBXPreferences.EXPORT_ENCODING, System.getProperty("file.encoding")); //$NON-NLS-1$
70 74
		preferences.put(TBXPreferences.EXPORT_COL_SEPARATOR, "\t"); //$NON-NLS-1$
71 75
		preferences.put(TBXPreferences.EXPORT_TXT_SEPARATOR, ""); //$NON-NLS-1$
72
		preferences.put(UI_LOCALE, "en"); //$NON-NLS-1$
76
		preferences.put(CONFIG_LOCALE, "en"); //$NON-NLS-1$
73 77
		
74 78
		preferences.put(UPDATE_LEVEL, "STABLE"); //$NON-NLS-1$
75 79
		
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/views/RConsole.java (revision 1772)
244 244
				//if (errorLogger.getMessagePrinter() == null) {
245 245
					//System.out.println("SET MESSAGEPRINTER OF THE RCONSOLE");
246 246
					if (errorLogger != null)
247
						errorLogger.addMessagePrinter(this);
247
						errorLogger.registerMessagePrinter(this);
248 248
					if (inputLogger != null)
249
						inputLogger.addMessagePrinter(this);
249
						inputLogger.registerMessagePrinter(this);
250 250
					readyToDisplay = true;
251 251
				//}
252 252
			} catch (RWorkspaceException e) {
tmp/org.txm.utils/src/org/txm/utils/StreamHog.java (revision 1772)
35 35
import org.txm.utils.logger.Log;
36 36

  
37 37
/**
38
 * The Class StreamHog.
38
 * The StreamHog read the given InputStream in a Thread until the InputStream is closed.
39 39
 * 
40 40
 * If a MessagePrinter is set, then the messages are displayed with the MessagePrinter and not in sys.out
41 41
 */
42 42
public class StreamHog extends Thread {
43 43

  
44 44
	InputStream is;
45
	boolean capture;
46
	String installPath;
47
	boolean go = true;
48

  
49 45
	BufferedReader br;
50 46
	ArrayList<MessagePrinter> messagePrinters = new ArrayList<MessagePrinter>();
51 47

  
52
	/** The lastline. */
53 48
	public String lastline;
54

  
49
	boolean log;
50
	
55 51
	/**
56 52
	 * Instantiates a new stream hog.
57 53
	 *
58 54
	 * @param is the is
59
	 * @param capture the capture
55
	 * @param log the capture
60 56
	 */
61
	public StreamHog(InputStream is, boolean capture) {
57
	public StreamHog(InputStream is, boolean log) {
62 58
		this.setName("");
63 59
		this.is = is;
64
		this.capture = capture;
60
		this.log = log;
65 61
		start();
66 62
	}
67 63
	
68
	public String getInstallPath() {
69
		return installPath;
64
	public String getLastMessage() {
65
		return lastline;
70 66
	}
71

  
67
	
72 68
	public InputStream getInputStream() {
73 69
		return is;
74 70
	}
......
86 82
			br = new BufferedReader(new InputStreamReader(is));
87 83
			String line = null;
88 84
			while ((line = br.readLine()) != null) {
89
				if (capture) { // we are supposed to capture the output from
90
					int i = line.indexOf("InstallPath"); //$NON-NLS-1$
91
					if (i >= 0) {
92
						String s = line.substring(i + 11).trim();
93
						int j = s.indexOf("REG_SZ"); //$NON-NLS-1$
94
						if (j >= 0)
95
							s = s.substring(j + 6).trim();
96
						installPath = s;
97
						System.out.println("R InstallPath = " + s);
98
					}
85
				if (log) { // we are supposed to capture the output from
86
					Log.info(this.getName()+">" + line); //$NON-NLS-1$
99 87
				}
100 88
				
101 89
				printMessage(line);
102
				Log.info(this.getName()+">" + line); //$NON-NLS-1$
103 90
				lastline = line;
104 91
			}
105 92
		} catch (Throwable e) {
106
			Log.fine("ERROR: broken process logging : "+e);
93
			Log.fine("ERROR: broken process logging : "+e); //$NON-NLS-1$
107 94
			org.txm.utils.logger.Log.printStackTrace(e);
108 95
		}
109 96
	}
110 97
	
111 98
	/**
112
	 * print the message if any MessagePrinter is set
99
	 * print the message to any registered MessagePrinter
113 100
	 * @param msg
114 101
	 */
115 102
	public void printMessage(String msg) {
116 103
		if (messagePrinters.size() > 0) {
117
			for (MessagePrinter mp : messagePrinters)
118
				mp.println(msg); //$NON-NLS-1$
104
			for (MessagePrinter mp : messagePrinters) {
105
				mp.println(msg);
106
			}
119 107
		}
120 108
	}
121 109

  
122
	public void addMessagePrinter(MessagePrinter mp) {
110
	/**
111
	 * Use this method to retrieve messages
112
	 * @param mp
113
	 */
114
	public void registerMessagePrinter(MessagePrinter mp) {
123 115
		this.messagePrinters.add(mp);
124 116
	}
125 117

  
......
130 122
	/**
131 123
	 * Sets the prints the.
132 124
	 *
133
	 * @param capture the new prints the
125
	 * @param log activate message logs if true
134 126
	 */
135
	public void setPrint(boolean capture)
136
	{
137
		this.capture = capture;
127
	public void setPrint(boolean log) {
128
		this.log = log;
138 129
	}
139

  
140
	public void stopLogging() {
141
		go = false;
142
	}
143 130
}
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RWorkspace.java (revision 1772)
1594 1594

  
1595 1595
	
1596 1596
	/**
1597

  
1597 1598
	 * Bar delegate call to {@link Connection#voidEval(String)}.
1598 1599
	 * 
1599 1600
	 * It is up to the caller to check if everything goes well (testing if the
......
1713 1714
	}
1714 1715

  
1715 1716
	/**
1716
	 * Start logger.
1717
	 *
1718
	 * @param streamHog the stream hog
1719
	 * @param streamHog2 the stream hog2
1720
	 * @return the r workspace
1721
	 */
1722
	public RWorkspace stopLogger() {
1723
		this.errorLogger.stopLogging();
1724
		this.inputLogger.stopLogging();
1725
		return null;
1726
	}
1727

  
1728
	/**
1729 1717
	 * To txt.
1730 1718
	 *
1731 1719
	 * @param file the file

Also available in: Unified diff