[365620] Content Model View gets NPE's if an element doesn't exist in the schema
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
index a9e6b5f..2f93c72 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2005, 2013 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 http://www.eclipse.org/legal/epl-v10.html
@@ -252,6 +252,7 @@
public static String Suggestion_Strategy_Strict;
public static String Element____1;
public static String Content_Model____2;
+ public static String ContentModel_ElementNotDescribed;
public static String Attribute____3;
public static String Data_Type____4;
public static String Enumerated_Values____5;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
index dc8c8ed..b14da0c 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2001, 2012 IBM Corporation and others.
+# Copyright (c) 2001, 2013 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
@@ -284,6 +284,7 @@
## tag info
Element____1=Element :
Content_Model____2=Content Model :
+ContentModel_ElementNotDescribed=The content model does not describe the selected element.
Attribute____3=Attribute :
Data_Type____4=Data Type :
Enumerated_Values____5=Enumerated Values :
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentmodel/CMListWorkbenchAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentmodel/CMListWorkbenchAdapter.java
index 08d4fd2..ac76d87 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentmodel/CMListWorkbenchAdapter.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentmodel/CMListWorkbenchAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 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
@@ -24,6 +24,7 @@
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor;
+import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
@@ -35,18 +36,26 @@
private GroupStack fGroupStack;
private CMDescriber fRoot;
- public CMListWorkbenchAdapter(CMElementDeclaration decl) {
- text = getFormattedLabel(decl.getNodeName(), decl.getMinOccur(), decl.getMaxOccur(), decl.getDataType());
- fDeclaration = decl;
- image = AbstractUIPlugin.imageDescriptorFromPlugin(XMLUIPlugin.ID, XMLEditorPluginImages.IMG_OBJ_ELEMENT);
+ private static final Object[] EMPTY = new Object[0];
- fGroupStack = new GroupStack();
- fRoot = new CMDescriber(decl);
+ public CMListWorkbenchAdapter(CMElementDeclaration decl) {
+ if (decl != null) {
+ text = getFormattedLabel(decl.getNodeName(), decl.getMinOccur(), decl.getMaxOccur(), decl.getDataType());
+ fDeclaration = decl;
+ image = AbstractUIPlugin.imageDescriptorFromPlugin(XMLUIPlugin.ID, XMLEditorPluginImages.IMG_OBJ_ELEMENT);
+
+ fGroupStack = new GroupStack();
+ fRoot = new CMDescriber(decl);
+ }
+ else {
+ text = XMLUIMessages.ContentModel_ElementNotDescribed;
+ image = AbstractUIPlugin.imageDescriptorFromPlugin(XMLUIPlugin.ID, XMLEditorPluginImages.IMG_OBJ_WARNING_OBJ);
+ }
}
public Object[] getChildren(Object o) {
/* TODO Use the CMElementDeclaration and ModelQuery to get the available children of the root element */
- return fRoot.getChildren(o);
+ return fRoot != null ? fRoot.getChildren(o) : EMPTY;
}
public ImageDescriptor getImageDescriptor(Object object) {