Bug 440469 - [model editor] add option to disable list tab persistence
of filter and columns

Change-Id: I1625b0ffa9cdede39f350939a8380460fec12fef
Signed-off-by: Steven Spungin <steven@spungin.tv>
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java
index 2b50157..acb7735 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  *
  * Contributors:
- *     Steven Spungin <steven@spungin.tv> - Bug 431735, Bug 437890
+ *     Steven Spungin <steven@spungin.tv> - Bug 431735, Bug 437890, Bug 440469
  ******************************************************************************/
 
 package org.eclipse.e4.tools.emf.editor3x;
@@ -28,6 +28,8 @@
 	private ColorFieldEditor fColorValueNotVisible;
 	private ColorFieldEditor fColorValueNotVisibleAndRendered;
 	private BooleanFieldEditor fShowSearch;
+	private BooleanFieldEditor fRememberColumns;
+	private BooleanFieldEditor fRememberFilters;
 
 	public ModelEditorPreferencePage() {
 	}
@@ -100,7 +102,7 @@
 				fShowXMIId.setPreferenceStore(getPreferenceStore());
 				fShowXMIId.load();
 			}
-			
+
 			{
 				Composite container = new Composite(group, SWT.NONE);
 				container.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
@@ -109,6 +111,29 @@
 				fShowSearch.setPreferenceStore(getPreferenceStore());
 				fShowSearch.load();
 			}
+
+		}
+
+		{
+			Group group = new Group(result, SWT.NONE);
+			group.setText("List Tab");
+			group.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+			group.setLayout(new GridLayout(2, false));
+
+			{
+				Composite container = new Composite(group, SWT.NONE);
+				container.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+
+				fRememberColumns = new BooleanFieldEditor("list-tab-remember-columns", "Remember column settings when reopening editor  ", container);
+				fRememberColumns.setPage(this);
+				fRememberColumns.setPreferenceStore(getPreferenceStore());
+				fRememberColumns.load();
+
+				fRememberFilters = new BooleanFieldEditor("list-tab-remember-filters", "Remember filter settings when reopening editor", container);
+				fRememberFilters.setPage(this);
+				fRememberFilters.setPreferenceStore(getPreferenceStore());
+				fRememberFilters.load();
+			}
 		}
 
 		return result;
@@ -122,6 +147,8 @@
 		fColorValueNotVisible.store();
 		fColorValueNotVisibleAndRendered.store();
 		fShowSearch.store();
+		fRememberColumns.store();
+		fRememberFilters.store();
 		return super.performOk();
 	}
 
@@ -133,6 +160,8 @@
 		fColorValueNotVisible.loadDefault();
 		fColorValueNotVisibleAndRendered.loadDefault();
 		fShowSearch.loadDefault();
+		fRememberColumns.loadDefault();
+		fRememberFilters.loadDefault();
 		super.performDefaults();
 	}
 
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java
index 7a9d2fc..e3d8143 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  *
  * Contributors:
- *     Steven Spungin <steven@spungin.tv> - Bug 431735, Bug 437890
+ *     Steven Spungin <steven@spungin.tv> - Bug 431735, Bug 437890, Bug 440469
  ******************************************************************************/
 
 package org.eclipse.e4.tools.emf.ui.internal;
@@ -36,12 +36,20 @@
 		if (pref.get("autoCreateElementId", null) == null) { //$NON-NLS-1$
 			pref.putBoolean("autoCreateElementId", true); //$NON-NLS-1$
 		}
-		
+
 		// TODO: After XMI tab is not forced disabled, this should default to
 		// true
 		if (pref.get("tab-form-search-show", null) == null) { //$NON-NLS-1$
 			pref.putBoolean("tab-form-search-show", false); //$NON-NLS-1$
 		}
+
+		if (pref.get("list-tab-remember-filters", null) == null) { //$NON-NLS-1$
+			pref.putBoolean("list-tab-remember-filters", false); //$NON-NLS-1$
+		}
+
+		if (pref.get("list-tab-remember-columns", null) == null) { //$NON-NLS-1$
+			pref.putBoolean("list-tab-remember-columns", false); //$NON-NLS-1$
+		}
 	}
 
 }
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
index 667cc81..c779244 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
@@ -6,7 +6,7 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *     Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555, Bug 436889, Bug 437372
+ *     Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555, Bug 436889, Bug 437372, Bug 440469
  *******************************************************************************/
 
 package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
@@ -237,69 +237,79 @@
 	// load custom column and filter settings
 	private void loadSettings() {
 		IEclipsePreferences pref = InstanceScope.INSTANCE.getNode("org.eclipse.e4.tools.emf.ui"); //$NON-NLS-1$
+
+		boolean restoreColumns = pref.getBoolean("list-tab-remember-columns", false); //$NON-NLS-1$
+		boolean restoreFilters = pref.getBoolean("list-tab-remember-filters", false); //$NON-NLS-1$
+		if (!restoreColumns && !restoreFilters) {
+			return;
+		}
+
 		String xml = pref.get("list-tab-xml", ""); //$NON-NLS-1$ //$NON-NLS-2$
 		if (E.notEmpty(xml)) {
 			try {
 				Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
 				XPath xpath = XPathFactory.newInstance().newXPath();
 				NodeList list;
-
-				// restore columns and column widths
-				list = (NodeList) xpath.evaluate("//columns/column", doc, XPathConstants.NODESET); //$NON-NLS-1$
-				for (int i = 0; i < list.getLength(); i++) {
-					Element ele = (Element) list.item(i);
-					TableColumn col;
-					String colName = xpath.evaluate("attribute/text()", ele); //$NON-NLS-1$
-					if (colName.isEmpty()) {
-						continue;
-					}
-					col = requiredColumns.get(colName);
-					if (col == null) {
-						col = addColumn(colName).getTableViewerColumn().getColumn();
-					}
-
-					// move it to the end of the list.
-					int currentIndex = TableViewerUtil.getVisibleColumnIndex(tvResults, col);
-					int[] order = tvResults.getTable().getColumnOrder();
-					for (int idx = 0; idx < order.length; idx++) {
-						if (order[idx] > currentIndex) {
-							order[idx]--;
-						} else if (order[idx] == currentIndex) {
-							order[idx] = order.length - 1;
+				if (restoreColumns) {
+					// restore columns and column widths
+					list = (NodeList) xpath.evaluate("//columns/column", doc, XPathConstants.NODESET); //$NON-NLS-1$
+					for (int i = 0; i < list.getLength(); i++) {
+						Element ele = (Element) list.item(i);
+						TableColumn col;
+						String colName = xpath.evaluate("attribute/text()", ele); //$NON-NLS-1$
+						if (colName.isEmpty()) {
+							continue;
 						}
-					}
-					tvResults.getTable().setColumnOrder(order);
+						col = requiredColumns.get(colName);
+						if (col == null) {
+							col = addColumn(colName).getTableViewerColumn().getColumn();
+						}
 
-					//					if ("Item".equals(colName)) { //$NON-NLS-1$
-					// col = colItem;
-					//					} else if ("Item".equals(colName)) { //$NON-NLS-1$
-					// col = colItem;
-					// }
+						// move it to the end of the list.
+						int currentIndex = TableViewerUtil.getVisibleColumnIndex(tvResults, col);
+						int[] order = tvResults.getTable().getColumnOrder();
+						for (int idx = 0; idx < order.length; idx++) {
+							if (order[idx] > currentIndex) {
+								order[idx]--;
+							} else if (order[idx] == currentIndex) {
+								order[idx] = order.length - 1;
+							}
+						}
+						tvResults.getTable().setColumnOrder(order);
 
-					String sWidth = xpath.evaluate("width/text()", ele); //$NON-NLS-1$
-					try {
-						col.setWidth(Integer.parseInt(sWidth));
-					} catch (Exception e) {
+						//					if ("Item".equals(colName)) { //$NON-NLS-1$
+						// col = colItem;
+						//					} else if ("Item".equals(colName)) { //$NON-NLS-1$
+						// col = colItem;
+						// }
+
+						String sWidth = xpath.evaluate("width/text()", ele); //$NON-NLS-1$
+						try {
+							col.setWidth(Integer.parseInt(sWidth));
+						} catch (Exception e) {
+						}
 					}
 				}
 
-				// restore filters
-				list = (NodeList) xpath.evaluate("//filters/filter", doc, XPathConstants.NODESET); //$NON-NLS-1$
-				for (int i = 0; i < list.getLength(); i++) {
-					Element ele = (Element) list.item(i);
-					String type = xpath.evaluate("type/text()", ele); //$NON-NLS-1$
-					String condition = xpath.evaluate("condition/text()", ele); //$NON-NLS-1$
-					String emptyOption = xpath.evaluate("emptyOption/text()", ele); //$NON-NLS-1$
-					if ("item".equals(type)) { //$NON-NLS-1$
-						filterByItem(condition);
-					} else if ("attribute".equals(type)) { //$NON-NLS-1$
-						EmptyFilterOption emptyFilterOption;
-						try {
-							emptyFilterOption = EmptyFilterOption.valueOf(emptyOption);
-						} catch (Exception e) {
-							emptyFilterOption = EmptyFilterOption.INCLUDE;
+				if (restoreFilters) {
+					// restore filters
+					list = (NodeList) xpath.evaluate("//filters/filter", doc, XPathConstants.NODESET); //$NON-NLS-1$
+					for (int i = 0; i < list.getLength(); i++) {
+						Element ele = (Element) list.item(i);
+						String type = xpath.evaluate("type/text()", ele); //$NON-NLS-1$
+						String condition = xpath.evaluate("condition/text()", ele); //$NON-NLS-1$
+						String emptyOption = xpath.evaluate("emptyOption/text()", ele); //$NON-NLS-1$
+						if ("item".equals(type)) { //$NON-NLS-1$
+							filterByItem(condition);
+						} else if ("attribute".equals(type)) { //$NON-NLS-1$
+							EmptyFilterOption emptyFilterOption;
+							try {
+								emptyFilterOption = EmptyFilterOption.valueOf(emptyOption);
+							} catch (Exception e) {
+								emptyFilterOption = EmptyFilterOption.INCLUDE;
+							}
+							filterByAttribute(condition, emptyFilterOption);
 						}
-						filterByAttribute(condition, emptyFilterOption);
 					}
 				}
 			} catch (Exception e) {