blob: a2a77bf5d00a592c5098eda540da243aadfc164a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2001, 2006 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
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.xsd.editor.internal.adapters;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xsd.adt.outline.ITreeElement;
import org.eclipse.wst.xsd.editor.XSDEditorPlugin;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDImport;
import org.eclipse.xsd.XSDInclude;
import org.eclipse.xsd.XSDModelGroupDefinition;
import org.eclipse.xsd.XSDRedefinableComponent;
import org.eclipse.xsd.XSDRedefine;
import org.eclipse.xsd.XSDRedefineContent;
import org.eclipse.xsd.XSDSchemaDirective;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
public class XSDSchemaDirectiveAdapter extends XSDBaseAdapter
{
public Image getImage()
{
XSDSchemaDirective object = (XSDSchemaDirective) target;
if (object instanceof XSDImport)
{
return XSDEditorPlugin.getXSDImage("icons/XSDImport.gif");
}
else if (object instanceof XSDInclude)
{
return XSDEditorPlugin.getXSDImage("icons/XSDInclude.gif");
}
else if (object instanceof XSDRedefine)
{
return XSDEditorPlugin.getXSDImage("icons/XSDRedefine.gif");
}
return null;
}
public String getText()
{
XSDSchemaDirective directive = (XSDSchemaDirective) target;
String result = directive.getSchemaLocation();
if (result == null)
result = "(" + XSDEditorPlugin.getXSDString("_UI_LABEL_NO_LOCATION_SPECIFIED") + ")";
if (result.equals(""))
result = "(" + XSDEditorPlugin.getXSDString("_UI_LABEL_NO_LOCATION_SPECIFIED") + ")";
return result;
}
public ITreeElement[] getChildren()
{
List list = new ArrayList();
if (target instanceof XSDRedefine)
{
XSDRedefine redefine = (XSDRedefine) target;
for (Iterator i = redefine.getContents().iterator(); i.hasNext();)
{
XSDRedefineContent redefineContent = (XSDRedefineContent) i.next();
if (redefineContent instanceof XSDAttributeGroupDefinition)
{
list.add((XSDAttributeGroupDefinition) redefine);
}
else if (redefineContent instanceof XSDModelGroupDefinition)
{
list.add((XSDModelGroupDefinition) redefineContent);
}
else if (redefineContent instanceof XSDRedefinableComponent)
{
XSDRedefinableComponent comp = (XSDRedefinableComponent) redefineContent;
if (comp instanceof XSDAttributeGroupDefinition)
{
list.add((XSDAttributeGroupDefinition) comp);
}
else if (comp instanceof XSDModelGroupDefinition)
{
list.add((XSDModelGroupDefinition) comp);
}
else if (comp instanceof XSDComplexTypeDefinition)
{
list.add((XSDComplexTypeDefinition) comp);
}
else if (comp instanceof XSDSimpleTypeDefinition)
{
list.add((XSDSimpleTypeDefinition) comp);
}
}
else if (redefineContent instanceof XSDComplexTypeDefinition)
{
list.add((XSDComplexTypeDefinition) redefineContent);
}
else if (redefineContent instanceof XSDSimpleTypeDefinition)
{
list.add((XSDSimpleTypeDefinition) redefineContent);
}
}
}
List adapterList = new ArrayList();
populateAdapterList(list, adapterList);
return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
}