package app.editors.settings;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import app.App;
import app.AppSettings;
import app.M;
import app.editors.BaseEditor;
import app.editors.Editors;
import app.editors.SimpleEditorInput;
import app.rcp.IniFile;
import app.util.UI;

public class SettingsPage extends BaseEditor {

	AppSettings settings = App.settings().clone();
	IniFile ini = IniFile.read();
	private IniFile originalIni = ini.clone();

	public static void open() {
		SimpleEditorInput input = new SimpleEditorInput("app.Settings");
		Editors.open(input, "app.Settings");
	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		super.init(site, input);
		setPartName(M.Settings);
	}

	@Override
	protected void addPages() {
		try {
			addPage(new Page());
		} catch (PartInitException e) {
			Logger log = LoggerFactory.getLogger(getClass());
			log.error("failed to add page", e);
		}
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		App.settings().setValues(settings);
		App.settings().save();
		dirty = false;
		if (!ini.equals(originalIni))
			ini.write();
		editorDirtyStateChanged();
	}

	private class Page extends FormPage {

		public Page() {
			super(SettingsPage.this, "SettingsPage", M.Settings);
		}

		@Override
		protected void createFormContent(IManagedForm mform) {
			FormToolkit tk = mform.getToolkit();
			ScrolledForm form = UI.formHeader(mform, M.Settings);
			Composite body = UI.formBody(form, mform.getToolkit());
			new DataSetSection(SettingsPage.this).render(body, tk);
			new ProfileSection(SettingsPage.this).render(body, tk);
			new AppSection(SettingsPage.this).render(body, tk);
			form.reflow(true);
		}
	}
}

@@ -619,24 +619,51 @@
 ditorInput;%0A
+import app.navi.Navigator;%0A
 import app.r
@@ -693,16 +693,41 @@
 util.UI;
+%0Aimport epd.util.Strings;
 %0A%0Apublic
@@ -1451,16 +1451,101 @@
 itor) %7B%0A
+%09%09boolean langChange = !Strings.nullOrEqual(App.settings().lang,%0A%09%09%09%09settings.lang);%0A
 %09%09App.se
@@ -1693,16 +1693,64 @@
 nged();%0A
+%09%09if (langChange) %7B%0A%09%09%09Navigator.refresh();%0A%09%09%7D%0A
 %09%7D%0A%0A%09pri

fix issue #11: refresh navigation tree after changing dataset language