Bug 497260 - Adding a new value to the JSON file collapses the Outline view

The commit also fixes bug 497253

Change-Id: I881f1acbec32c1921456b78f3243ddb808f0a99b
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONSelectionConvertorFactory.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONSelectionConvertorFactory.java
index 99e5ab1..69f35f1 100644
--- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONSelectionConvertorFactory.java
+++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/editor/JSONSelectionConvertorFactory.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2008, 2012 IBM Corporation and others.

+ * Copyright (c) 2008, 2016 IBM Corporation and others.

  * 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

@@ -20,6 +20,7 @@
 import org.eclipse.wst.json.core.document.IJSONDocument;

 import org.eclipse.wst.json.core.document.IJSONModel;

 import org.eclipse.wst.json.core.document.IJSONNode;

+import org.eclipse.wst.json.core.document.IJSONObject;

 import org.eclipse.wst.json.ui.internal.Logger;

 import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;

 import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;

@@ -98,11 +99,7 @@
 			if (model != null) {

 				IndexedRegion region = model.getIndexedRegion(start);

 

-				/*

-				 * in JSON docs whitespace is owned by the style sheet this is

-				 * to find the first none whitespace region

-				 */

-				if (region instanceof IJSONDocument) {

+				if (region instanceof IJSONObject || region instanceof IJSONDocument) {

 					try {

 						String selection = model.getStructuredDocument().get(

 								start, end);

diff --git a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/views/contentoutline/JSONContentOutlineConfiguration.java b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/views/contentoutline/JSONContentOutlineConfiguration.java
index 8ae08e4..71f43cc 100644
--- a/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/views/contentoutline/JSONContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/views/contentoutline/JSONContentOutlineConfiguration.java
@@ -1,5 +1,5 @@
 /**
- *  Copyright (c) 2013-2014 Angelo ZERR.
+ *  Copyright (c) 2013-2016 Angelo ZERR.
  *  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
@@ -10,7 +10,6 @@
  */
 package org.eclipse.wst.json.ui.views.contentoutline;
 
-import org.eclipse.wst.json.core.util.JSONUtil;
 import org.eclipse.jface.action.IContributionItem;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.IContentProvider;
@@ -19,7 +18,10 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.wst.json.core.document.IJSONArray;
 import org.eclipse.wst.json.core.document.IJSONNode;
+import org.eclipse.wst.json.core.document.IJSONPair;
+import org.eclipse.wst.json.core.document.IJSONValue;
 import org.eclipse.wst.json.ui.internal.JSONUIPlugin;
 import org.eclipse.wst.json.ui.internal.contentoutline.JFaceNodeContentProvider;
 import org.eclipse.wst.json.ui.internal.contentoutline.JFaceNodeLabelProvider;
@@ -78,7 +80,11 @@
 		if (o instanceof IJSONNode) {
 			node = (IJSONNode) o;
 			if (node.getOwnerPairNode() != null) {
-				return node.getOwnerPairNode();
+				IJSONPair owner = node.getOwnerPairNode();
+				IJSONValue value = owner.getValue();
+				if (!(value instanceof IJSONArray)) {
+					return node.getOwnerPairNode();
+				}
 			}
 			/*
 			 * short nodeType = node.getNodeType(); if (node instanceof