/*******************************************************************************
 * Copyright (c) 2014 Liviu Ionescu.
 * 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
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Liviu Ionescu - initial implementation.
 *******************************************************************************/

package ilg.gnumcueclipse.packs.core;

import java.io.File;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;

/**
 * Class used to initialise default preference values.
 */
public class PreferencesInitializer extends AbstractPreferenceInitializer {

	public void initializeDefaultPreferences() {

		// System.out
		// .println("PreferenceInitializer.initializeDefaultPreferences()");

		IPreferenceStore store = Preferences.getPreferenceStore();

		// Get workspace
		IWorkspace workspace = ResourcesPlugin.getWorkspace();

		// Compute workspace/../Packages
		IPath workspacePath = workspace.getRoot().getLocation();
		IPath workspaceParentPath = workspacePath.removeLastSegments(1);
		IPath packagesPath = workspaceParentPath.append("Packages");
		// System.out.println(packagesPath.toOSString());

		// Create folder if needed
		File packagesFolder = new File(packagesPath.toOSString());
		if (!packagesFolder.exists()) {
			packagesFolder.mkdir();
			// System.out.println(packagesFolder + " created");
		}

		store.setDefault(Preferences.PACKS_FOLDER_PATH, packagesPath.toOSString());

		store.setDefault(Preferences.PACKS_MACRO_NAME, Preferences.DEFAULT_MACRO_NAME);
	}

}

@@ -1114,70 +1114,8 @@
 );%0A%0A
-%09%09IPreferenceStore store = Preferences.getPreferenceStore();%0A%0A
 %09%09//
@@ -1470,216 +1470,66 @@
 %0A%0A%09%09
-// Create folder if needed%0A%09%09File packagesFolder = new File(packagesPath.toOSString());%0A%09%09if (!packagesFolder.exists()) %7B%0A%09%09%09packagesFolder.mkdir();%0A%09%09%09// System.out.println(packagesFolder + %22 created%22);%0A%09%09%7D%0A
+IPreferenceStore store = Preferences.getPreferenceStore();
 %0A%09%09s
@@ -1603,17 +1603,16 @@
 ing());%0A
-%0A
 %09%09store.
@@ -1686,13 +1686,337 @@
 NAME);%0A%09
+%09%0A%09%09// Read back the actual value.%0A%09%09String folderPath = store.getString(Preferences.PACKS_FOLDER_PATH);%0A%0A%09%09File packagesFolder = new File(folderPath);%0A%09%09if (!packagesFolder.exists()) %7B%0A%09%09%09packagesFolder.mkdir();%0A%09%09%09if (Activator.getInstance().isDebugging()) %7B%0A%09%09%09  System.out.println(packagesFolder + %22 created%22);%0A%09%09%09%7D%0A%09%09%7D%0A%09
 %7D
-%0A
 %0A%7D%0A

create Packages in the right location, not the default one