Bug 573421 - Avoid local history for derived files (UI)

Added a configuration whether history for derived files is kept.
Off (no history for derived files) by default.

Change-Id: I9e4e7fdeb1cbb690c400ce03d231feff82b4ca08
Signed-off-by: Joerg Kubitz <jkubitz-eclipse@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/180357
Tested-by: Lars Vogel <Lars.Vogel@vogella.com>
Reviewed-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java
index f754499..2662796 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java
@@ -624,6 +624,7 @@
 	public static String FileHistory_entries;
 	public static String FileHistory_diskSpace;
 	public static String FileHistory_applyPolicy;
+	public static String FileHistory_keepDerivedState;
 	public static String FileHistory_mustBePositive;
 	public static String FileHistory_invalid;
 	public static String FileHistory_exceptionSaving;
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/FileStatesPage.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/FileStatesPage.java
index f1aa9ee..39c40c9 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/FileStatesPage.java
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/FileStatesPage.java
@@ -62,6 +62,8 @@
 
 	private Button applyPolicyButton;
 
+	private Button keepDerivedStateButton;
+
 	private ArrayList<Control> dependentControls = new ArrayList<>();
 
 	//Choose a maximum to prevent OutOfMemoryErrors
@@ -117,8 +119,8 @@
 	 */
 	private void checkState() {
 		// Assume invalid if the controls not created yet
-		if (longevityText == null || maxStatesText == null || maxStateSizeText == null
-				|| applyPolicyButton == null) {
+		if (longevityText == null || maxStatesText == null || maxStateSizeText == null || applyPolicyButton == null
+				|| keepDerivedStateButton == null) {
 			setValid(false);
 			return;
 		}
@@ -179,6 +181,9 @@
 		layout.marginWidth= 0;
 		composite.setLayout(layout);
 
+		this.keepDerivedStateButton = addCheckBox(IDEWorkbenchMessages.FileHistory_keepDerivedState,
+				description.isKeepDerivedState(), composite);
+
 		this.applyPolicyButton = addCheckBox(IDEWorkbenchMessages.FileHistory_applyPolicy, description
 				.isApplyFileStatePolicy(), composite);
 
@@ -260,6 +265,7 @@
 		this.maxStatesText.setText(prefs
 				.getDefaultString(ResourcesPlugin.PREF_MAX_FILE_STATES));
 		this.maxStateSizeText.setText(String.valueOf(megabytes));
+		this.keepDerivedStateButton.setSelection(prefs.getDefaultBoolean(ResourcesPlugin.PREF_KEEP_DERIVED_STATE));
 		this.applyPolicyButton.setSelection(prefs
 				.getDefaultBoolean(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY));
 		checkState();
@@ -274,6 +280,7 @@
 		long longevityValue = validateLongTextEntry(longevityText, DAY_LENGTH);
 		int maxFileStates = validateMaxFileStates();
 		long maxStateSize = validateMaxFileStateSize();
+		boolean keepDerivedState = keepDerivedStateButton.getSelection();
 		boolean applyPolicy = applyPolicyButton.getSelection();
 		if (longevityValue == FAILED_VALUE || maxFileStates == FAILED_VALUE
 				|| maxStateSize == FAILED_VALUE) {
@@ -284,6 +291,7 @@
 		description.setFileStateLongevity(longevityValue * DAY_LENGTH);
 		description.setMaxFileStates(maxFileStates);
 		description.setMaxFileStateSize(maxStateSize * MEGABYTES);
+		description.setKeepDerivedState(keepDerivedState);
 		description.setApplyFileStatePolicy(applyPolicy);
 
 		try {
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties
index 8616644..418655b 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties
@@ -606,6 +606,7 @@
 FileHistory_exceptionSaving = Internal error saving local history
 FileHistory_aboveMaxEntries = Above maximum Entries per file: {0}
 FileHistory_aboveMaxFileSize = Above maximum file size value: {0}
+FileHistory_keepDerivedState = History for derived files
 FileHistory_restartNote = The 'Maximum entries per file' and the 'Days to keep files' values\nare only applied when compacting the local history on shutdown.
 
 # --- Perspectives ---