org.eclipse.wst.xsd.ui_1.2.404.v201105050216

16:49:35.931 INFO  jd.cli.Main - Decompiling org.eclipse.wst.xsd.ui_1.2.404.v201105050216.jar
package org.eclipse.wst.xsd.ui.internal.actions;

import org.eclipse.gef.ui.parts.AbstractEditPartViewer;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDNamedComponent;
import org.w3c.dom.Element;

class CreateElementAction$1
  implements Runnable
{
  final CreateElementAction this$0;
  
  CreateElementAction$1(CreateElementAction paramCreateElementAction, XSDConcreteComponent paramXSDConcreteComponent, Element paramElement) {}
  
  public void run()
  {
    if ((val$comp instanceof XSDAttributeDeclaration))
    {
      if ((((XSDAttributeDeclaration)val$comp).getContainer() instanceof XSDAttributeUse))
      {
        if ((val$comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition)) {
          this$0.selectionProvider.setSelection(new StructuredSelection(val$comp.getContainer()));
        } else if ((val$comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition))
        {
          if (XSDDOMHelper.inputEquals(val$child, "attribute", true)) {
            this$0.selectionProvider.setSelection(new StructuredSelection(val$comp.getContainer()));
          } else {
            this$0.selectionProvider.setSelection(new StructuredSelection(val$comp));
          }
        }
        else {
          this$0.selectionProvider.setSelection(new StructuredSelection(val$comp));
        }
      }
      else {
        this$0.selectionProvider.setSelection(new StructuredSelection(val$comp));
      }
    }
    else {
      this$0.selectionProvider.setSelection(new StructuredSelection(val$comp));
    }
    if ((val$comp instanceof XSDNamedComponent)) {
      (this$0.sourceContext instanceof AbstractEditPartViewer);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

import java.util.List;
import org.eclipse.gef.ui.parts.AbstractEditPartViewer;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML;
import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDNamedComponent;
import org.eclipse.xsd.XSDSchema;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;

public class CreateElementAction
  extends Action
{
  protected String description;
  protected Element parentNode;
  protected ISelectionProvider selectionProvider;
  protected XSDSchema xsdSchema;
  protected Object sourceContext;
  
  public CreateElementAction() {}
  
  public CreateElementAction(String text)
  {
    super(text);
  }
  
  public CreateElementAction(String text, ImageDescriptor image)
  {
    super(text, image);
  }
  
  public void setXSDSchema(XSDSchema xsdSchema)
  {
    this.xsdSchema = xsdSchema;
  }
  
  public void setSelectionProvider(ISelectionProvider selectionProvider)
  {
    this.selectionProvider = selectionProvider;
  }
  
  public void setSourceContext(Object sourceContext)
  {
    this.sourceContext = sourceContext;
  }
  
  public Element getParentNode()
  {
    return parentNode;
  }
  
  public void setParentNode(Element parentNode)
  {
    this.parentNode = parentNode;
  }
  
  boolean isGlobal = false;
  protected Node relativeNode;
  protected String elementTag;
  protected List attributes;
  
  public void setIsGlobal(boolean isGlobal)
  {
    this.isGlobal = isGlobal;
  }
  
  public boolean getIsGlobal()
  {
    return isGlobal;
  }
  
  public void setElementTag(String elementTag)
  {
    this.elementTag = elementTag;
  }
  
  public DocumentImpl getDocument()
  {
    return (DocumentImpl)getParentNode().getOwnerDocument();
  }
  
  public void beginRecording(String description)
  {
    getDocument().getModel().beginRecording(this, description);
  }
  
  public void endRecording()
  {
    DocumentImpl doc = getDocument();
    
    doc.getModel().endRecording(this);
  }
  
  public Element createAndAddNewChildElement()
  {
    String prefix = parentNode.getPrefix();
    prefix = prefix + ":";
    Element childNode = getDocument().createElementNS("http://www.w3.org/2001/XMLSchema", prefix + elementTag);
    if (getAttributes() != null)
    {
      List attributes = getAttributes();
      for (int i = 0; i < attributes.size(); i++)
      {
        DOMAttribute attr = (DOMAttribute)attributes.get(i);
        childNode.setAttribute(attr.getName(), attr.getValue());
      }
    }
    if (getRelativeNode() == null) {
      parentNode.appendChild(childNode);
    } else {
      parentNode.insertBefore(childNode, getRelativeNode());
    }
    if ((isGlobal) && (getRelativeNode() == null))
    {
      Text textNode = getDocument().createTextNode("\n\n");
      parentNode.appendChild(textNode);
    }
    else if ((isGlobal) && (getRelativeNode() != null))
    {
      Text textNode = getDocument().createTextNode("\n\n");
      parentNode.insertBefore(textNode, getRelativeNode());
    }
    formatChild(childNode);
    
    return childNode;
  }
  
  protected void formatChild(Element child)
  {
    if ((child instanceof IDOMNode))
    {
      IDOMModel model = ((IDOMNode)child).getModel();
      try
      {
        model.aboutToChangeModel();
        
        IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
        formatProcessor.formatNode(child);
      }
      finally
      {
        model.changedModel();
      }
    }
  }
  
  public void run()
  {
    beginRecording(getDescription());
    final Element child = createAndAddNewChildElement();
    endRecording();
    if (selectionProvider != null)
    {
      final XSDConcreteComponent comp = xsdSchema.getCorrespondingComponent(child);
      
      Runnable runnable = new Runnable()
      {
        public void run()
        {
          if ((comp instanceof XSDAttributeDeclaration))
          {
            if ((((XSDAttributeDeclaration)comp).getContainer() instanceof XSDAttributeUse))
            {
              if ((comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition)) {
                selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
              } else if ((comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition))
              {
                if (XSDDOMHelper.inputEquals(child, "attribute", true)) {
                  selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                } else {
                  selectionProvider.setSelection(new StructuredSelection(comp));
                }
              }
              else {
                selectionProvider.setSelection(new StructuredSelection(comp));
              }
            }
            else {
              selectionProvider.setSelection(new StructuredSelection(comp));
            }
          }
          else {
            selectionProvider.setSelection(new StructuredSelection(comp));
          }
          if ((comp instanceof XSDNamedComponent)) {
            (sourceContext instanceof AbstractEditPartViewer);
          }
        }
      };
      Display.getDefault().timerExec(50, runnable);
    }
  }
  
  public Node getRelativeNode()
  {
    return relativeNode;
  }
  
  public void setRelativeNode(Node relativeNode)
  {
    this.relativeNode = relativeNode;
  }
  
  public String getDescription()
  {
    if (description == null) {
      return getText();
    }
    return description;
  }
  
  public void setDescription(String description)
  {
    this.description = description;
  }
  
  public List getAttributes()
  {
    return attributes;
  }
  
  public void setAttributes(List attributes)
  {
    this.attributes = attributes;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

public class DOMAttribute
{
  protected String name;
  protected String value;
  
  public DOMAttribute() {}
  
  public DOMAttribute(String name, String value)
  {
    this.name = name;
    this.value = value;
  }
  
  public String getValue()
  {
    return value;
  }
  
  public void setValue(String value)
  {
    this.value = value;
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IEditorPart;

public abstract interface IXSDToolbarAction
  extends IAction
{
  public abstract void setEditorPart(IEditorPart paramIEditorPart);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.IXSDToolbarAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeGroupContent;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
import org.w3c.dom.Node;

public class MoveXSDAttributeAction
  extends MoveXSDBaseAction
{
  private static int INSERT_BEFORE = 0;
  private static int INSERT_AFTER = 1;
  private static int INSERT_DIRECT = 2;
  protected List selectedNodes;
  protected Node parentNode;
  protected Node previousRefChild;
  protected Node nextRefChild;
  int insertType;
  XSDConcreteComponent parentComponent;
  XSDConcreteComponent selected;
  XSDConcreteComponent previousRefComponent;
  XSDConcreteComponent nextRefComponent;
  boolean insertAtEnd = true;
  
  public MoveXSDAttributeAction(XSDConcreteComponent parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent)
  {
    this.parentComponent = parentComponent;
    this.selected = selected;
    previousRefComponent = previousRefChildComponent;
    nextRefComponent = nextRefChildComponent;
    if (parentComponent == null) {
      return;
    }
    parentNode = parentComponent.getElement();
    nextRefChild = (nextRefChildComponent != null ? nextRefChildComponent.getElement() : null);
    previousRefChild = (previousRefChildComponent != null ? previousRefChildComponent.getElement() : null);
    if (nextRefComponent != null) {
      if (nextRefComponent.getContainer().getContainer() == parentComponent) {
        insertType = INSERT_BEFORE;
      }
    }
    if (previousRefComponent != null) {
      if (previousRefComponent.getContainer().getContainer() == parentComponent) {
        insertType = INSERT_AFTER;
      }
    }
    if ((nextRefChildComponent == null) && (previousRefChildComponent == null)) {
      insertType = INSERT_DIRECT;
    }
  }
  
  public MoveXSDAttributeAction(XSDConcreteComponent parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent, boolean insertAtEnd)
  {
    this(parentComponent, selected, previousRefChildComponent, nextRefChildComponent);
  }
  
  public boolean canMove()
  {
    boolean result = true;
    if (((nextRefComponent instanceof XSDElementDeclaration)) || ((previousRefComponent instanceof XSDElementDeclaration)) || (parentComponent == null)) {
      return false;
    }
    return result;
  }
  
  public void run()
  {
    if ((parentComponent instanceof XSDAttributeGroupDefinition)) {
      moveUnderXSDAttributeGroupDefinition((XSDAttributeGroupDefinition)parentComponent);
    } else if ((parentComponent instanceof XSDComplexTypeDefinition)) {
      moveUnderXSDComplexTypeDefinition((XSDComplexTypeDefinition)parentComponent);
    }
  }
  
  protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup)
  {
    int originalIndex = 0;
    for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext();)
    {
      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent)iterator.next();
      if ((attributeGroupContent instanceof XSDAttributeUse))
      {
        XSDAttributeDeclaration attribute = ((XSDAttributeUse)attributeGroupContent).getContent();
        if (attribute == selected)
        {
          parentGroup.getContents().remove(attribute.getContainer());
          break;
        }
      }
      originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    if (insertType == INSERT_DIRECT)
    {
      XSDConcreteComponent container = selected.getContainer();
      if (container != null)
      {
        if (insertAtEnd) {
          ((XSDAttributeGroupDefinition)parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
        } else {
          ((XSDAttributeGroupDefinition)parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
        }
        addedBack = true;
      }
      return;
    }
    List attributeGroupContents = parentGroup.getContents();
    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext();)
    {
      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent)iterator.next();
      if ((attributeGroupContent instanceof XSDAttributeUse))
      {
        XSDAttributeDeclaration attribute = ((XSDAttributeUse)attributeGroupContent).getContent();
        if (insertType == INSERT_BEFORE)
        {
          if (attribute == nextRefComponent)
          {
            parentGroup.getContents().add(index, selected.getContainer());
            addedBack = true;
            break;
          }
          if ((selected == nextRefComponent) && (originalIndex == index))
          {
            parentGroup.getContents().add(index, selected.getContainer());
            addedBack = true;
            break;
          }
        }
        else if (insertType == INSERT_AFTER)
        {
          if (attribute == previousRefComponent)
          {
            parentGroup.getContents().add(index + 1, selected.getContainer());
            addedBack = true;
            break;
          }
          if ((selected == previousRefComponent) && (originalIndex == index))
          {
            parentGroup.getContents().add(index, selected.getContainer());
            addedBack = true;
            break;
          }
        }
      }
      index++;
    }
    if (attributeGroupContents.size() == 0)
    {
      parentGroup.getContents().add(selected.getContainer());
      addedBack = true;
    }
    if (!addedBack) {
      parentGroup.getContents().add(originalIndex, selected.getContainer());
    }
  }
  
  protected void moveUnderXSDComplexTypeDefinition(XSDComplexTypeDefinition complexType)
  {
    int originalIndex = 0;
    for (Iterator iterator = complexType.getAttributeContents().iterator(); iterator.hasNext();)
    {
      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent)iterator.next();
      if ((attributeGroupContent instanceof XSDAttributeUse))
      {
        XSDAttributeDeclaration attribute = ((XSDAttributeUse)attributeGroupContent).getContent();
        if (attribute == selected)
        {
          complexType.getAttributeContents().remove(attribute.getContainer());
          break;
        }
      }
      originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    List attributeGroupContents = complexType.getAttributeContents();
    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext();)
    {
      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent)iterator.next();
      if ((attributeGroupContent instanceof XSDAttributeUse))
      {
        XSDAttributeDeclaration attribute = ((XSDAttributeUse)attributeGroupContent).getContent();
        if (insertType == INSERT_AFTER)
        {
          if (attribute == previousRefComponent)
          {
            complexType.getAttributeContents().add(index + 1, selected.getContainer());
            addedBack = true;
            break;
          }
        }
        else if (insertType == INSERT_BEFORE) {
          if (attribute == nextRefComponent)
          {
            complexType.getAttributeContents().add(index, selected.getContainer());
            addedBack = true;
            break;
          }
        }
      }
      index++;
    }
    if (attributeGroupContents.size() == 0)
    {
      complexType.getAttributeContents().add(selected.getContainer());
      addedBack = true;
    }
    if (!addedBack) {
      complexType.getAttributeContents().add(originalIndex, selected.getContainer());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.MoveXSDAttributeAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

import org.eclipse.jface.action.Action;

public class MoveXSDBaseAction
  extends Action
{
  public boolean canMove()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.MoveXSDBaseAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDParticleContent;
import org.w3c.dom.Node;

public class MoveXSDElementAction
  extends MoveXSDBaseAction
{
  private static int INSERT_BEFORE = 0;
  private static int INSERT_AFTER = 1;
  private static int INSERT_DIRECT = 2;
  protected List selectedNodes;
  protected Node parentNode;
  protected Node previousRefChild;
  protected Node nextRefChild;
  int insertType;
  XSDModelGroup parentModelGroup;
  XSDConcreteComponent selected;
  XSDConcreteComponent previousRefComponent;
  XSDConcreteComponent nextRefComponent;
  boolean insertAtEnd = true;
  
  public MoveXSDElementAction(XSDModelGroup parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent)
  {
    parentModelGroup = parentComponent;
    this.selected = selected;
    previousRefComponent = previousRefChildComponent;
    nextRefComponent = nextRefChildComponent;
    if (parentComponent == null) {
      return;
    }
    parentNode = parentComponent.getElement();
    nextRefChild = (nextRefChildComponent != null ? nextRefChildComponent.getElement() : null);
    previousRefChild = (previousRefChildComponent != null ? previousRefChildComponent.getElement() : null);
    if (nextRefComponent != null) {
      if (nextRefComponent.getContainer().getContainer() == parentModelGroup) {
        insertType = INSERT_BEFORE;
      }
    }
    if (previousRefComponent != null) {
      if (previousRefComponent.getContainer().getContainer() == parentModelGroup) {
        insertType = INSERT_AFTER;
      }
    }
    if ((nextRefChildComponent == null) && (previousRefChildComponent == null)) {
      insertType = INSERT_DIRECT;
    }
  }
  
  public MoveXSDElementAction(XSDModelGroup parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent, boolean insertAtEnd)
  {
    this(parentComponent, selected, previousRefChildComponent, nextRefChildComponent);
  }
  
  public boolean canMove()
  {
    boolean result = true;
    if (((nextRefComponent instanceof XSDAttributeDeclaration)) || ((previousRefComponent instanceof XSDAttributeDeclaration)) || (parentModelGroup == null)) {
      return false;
    }
    return result;
  }
  
  public void run()
  {
    int originalIndex = 0;
    for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext();)
    {
      XSDParticle particle = (XSDParticle)particles.next();
      XSDParticleContent particleContent = particle.getContent();
      if (particleContent == selected)
      {
        parentModelGroup.getContents().remove(particle);
        break;
      }
      originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    if (insertType == INSERT_DIRECT)
    {
      XSDConcreteComponent container = selected.getContainer();
      if (container != null)
      {
        XSDConcreteComponent container2 = container.getContainer();
        if ((container2 instanceof XSDModelGroup)) {
          ((XSDModelGroup)container2).getContents().remove(container);
        }
        if (insertAtEnd) {
          parentModelGroup.getContents().add(container);
        } else {
          parentModelGroup.getContents().add(0, container);
        }
        addedBack = true;
      }
      return;
    }
    List particles = parentModelGroup.getContents();
    for (Iterator iterator = particles.iterator(); iterator.hasNext();)
    {
      XSDParticle particle = (XSDParticle)iterator.next();
      XSDParticleContent particleContent = particle.getContent();
      if (insertType == INSERT_BEFORE)
      {
        if (particleContent == nextRefComponent)
        {
          parentModelGroup.getContents().add(index, selected.getContainer());
          addedBack = true;
          break;
        }
        if ((selected == nextRefComponent) && (originalIndex == index))
        {
          parentModelGroup.getContents().add(index, selected.getContainer());
          addedBack = true;
          break;
        }
      }
      else if (insertType == INSERT_AFTER)
      {
        if (particleContent == previousRefComponent)
        {
          parentModelGroup.getContents().add(index + 1, selected.getContainer());
          addedBack = true;
          break;
        }
        if ((selected == previousRefComponent) && (originalIndex == index))
        {
          parentModelGroup.getContents().add(index, selected.getContainer());
          addedBack = true;
          break;
        }
      }
      index++;
    }
    if (particles.size() == 0)
    {
      parentModelGroup.getContents().add(selected.getContainer());
      addedBack = true;
    }
    if (!addedBack) {
      parentModelGroup.getContents().add(originalIndex, selected.getContainer());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.MoveXSDElementAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.actions;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager;
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.util.XMLCommonResources;
import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNamespaceInformationCommand;
import org.eclipse.wst.xsd.ui.internal.common.util.Messages;
import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
import org.eclipse.wst.xsd.ui.internal.nsedit.SchemaPrefixChangeHandler;
import org.eclipse.wst.xsd.ui.internal.nsedit.TargetNamespaceChangeHandler;
import org.eclipse.wst.xsd.ui.internal.widgets.XSDEditSchemaInfoDialog;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDConstants;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XSDEditNamespacesAction
  extends Action
{
  private Element element;
  private String resourceLocation;
  private XSDSchema xsdSchema;
  private DOMNamespaceInfoManager namespaceInfoManager = new DOMNamespaceInfoManager();
  
  public XSDEditNamespacesAction(String label, Element element, Node node)
  {
    setText(label);
    
    this.element = element;
    
    resourceLocation = "dummy";
  }
  
  public XSDEditNamespacesAction(String label, Element element, Node node, XSDSchema schema)
  {
    this(label, element, node);
    xsdSchema = schema;
  }
  
  public void run()
  {
    if (element != null)
    {
      Shell shell = XMLCommonResources.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
      String targetNamespace = null;
      if (xsdSchema != null) {
        targetNamespace = xsdSchema.getTargetNamespace();
      }
      XSDEditSchemaInfoDialog dialog = new XSDEditSchemaInfoDialog(shell, new Path(resourceLocation), targetNamespace);
      
      List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(element);
      List oldNamespaceInfoList = NamespaceInfo.cloneNamespaceInfoList(namespaceInfoList);
      for (Iterator i = namespaceInfoList.iterator(); i.hasNext();)
      {
        NamespaceInfo info = (NamespaceInfo)i.next();
        NamespaceInfo oldCopy = new NamespaceInfo(info);
        info.setProperty("oldCopy", oldCopy);
      }
      dialog.setNamespaceInfoList(namespaceInfoList);
      dialog.create();
      dialog.getShell().setSize(500, 400);
      dialog.getShell().setText(XMLCommonResources.getInstance().getString("_UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE"));
      dialog.setBlockOnOpen(true);
      dialog.open();
      
      String xsdPrefix = null;
      String origXSDPrefix = xsdSchema.getSchemaForSchemaQNamePrefix();
      String newTNSPrefix = "";
      if (dialog.getReturnCode() == 0)
      {
        Element xsdSchemaElement = xsdSchema.getElement();
        DocumentImpl doc = (DocumentImpl)xsdSchemaElement.getOwnerDocument();
        
        List newInfoList = dialog.getNamespaceInfoList();
        
        Map prefixMapping = createPrefixMapping(oldNamespaceInfoList, namespaceInfoList);
        
        String origTNSPrefix = null;
        Map origPrefixMap = xsdSchema.getQNamePrefixToNamespaceMap();
        for (Iterator iter = origPrefixMap.keySet().iterator(); iter.hasNext();)
        {
          String key = (String)iter.next();
          String ns = (String)origPrefixMap.get(key);
          if (((targetNamespace == null) && (ns == null)) || ((targetNamespace != null) && (targetNamespace.equals(ns))))
          {
            origTNSPrefix = key;
            break;
          }
        }
        Map map2 = new Hashtable();
        for (Iterator iter = newInfoList.iterator(); iter.hasNext();)
        {
          NamespaceInfo ni = (NamespaceInfo)iter.next();
          String pref = prefix;
          String uri = uri;
          if (pref == null) {
            pref = "";
          }
          if (uri == null) {
            uri = "";
          }
          if (XSDConstants.isSchemaForSchemaNamespace(uri)) {
            xsdPrefix = pref;
          }
          if (uri.equals(dialog.getTargetNamespace())) {
            newTNSPrefix = pref;
          }
          map2.put(pref, uri);
        }
        if (map2.size() > 0) {
          try
          {
            doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_NAMESPACE_CHANGE"));
            boolean targetNamespaceChanged = ((targetNamespace != null) && (!targetNamespace.equals(dialog.getTargetNamespace()))) || ((targetNamespace == null) && (dialog.getTargetNamespace() != null));
            boolean tnsPrefixChanged = !newTNSPrefix.equals(origTNSPrefix);
            boolean xsdPrefixChanged = (origXSDPrefix != null) || (!xsdPrefix.equals("")) || ((origXSDPrefix != null) && (!origXSDPrefix.equals(xsdPrefix)));
            
            xsdSchema.setIncrementalUpdate(false);
            if (tnsPrefixChanged)
            {
              prefixMapping.remove(origTNSPrefix);
              UpdateNamespaceInformationCommand command = new UpdateNamespaceInformationCommand(Messages._UI_ACTION_NAMESPACE_INFORMATION_CHANGE, xsdSchema, newTNSPrefix, targetNamespace);
              command.execute();
              xsdSchema.update();
            }
            if (targetNamespaceChanged)
            {
              xsdSchema.setTargetNamespace(dialog.getTargetNamespace());
              
              TargetNamespaceChangeHandler targetNamespaceChangeHandler = new TargetNamespaceChangeHandler(xsdSchema, targetNamespace, dialog.getTargetNamespace());
              targetNamespaceChangeHandler.resolve();
            }
            if (prefixMapping.size() > 0) {
              for (Iterator iter = prefixMapping.keySet().iterator(); iter.hasNext();)
              {
                String oldPrefix = (String)iter.next();
                String newPrefix = (String)prefixMapping.get(oldPrefix);
                
                String ns = (String)origPrefixMap.get(oldPrefix);
                SchemaPrefixChangeHandler spch = new SchemaPrefixChangeHandler(xsdSchema, newPrefix, ns != null ? ns : "");
                spch.resolve();
              }
            }
            namespaceInfoManager.removeNamespaceInfo(element);
            namespaceInfoManager.addNamespaceInfo(element, newInfoList, false);
            if (xsdPrefixChanged)
            {
              if ((xsdPrefix != null) && (xsdPrefix.length() == 0)) {
                xsdSchema.setSchemaForSchemaQNamePrefix(null);
              } else {
                xsdSchema.setSchemaForSchemaQNamePrefix(xsdPrefix);
              }
              namespaceInfoManager.removeNamespaceInfo(element);
              namespaceInfoManager.addNamespaceInfo(element, newInfoList, false);
              xsdSchema.setIncrementalUpdate(true);
              
              SchemaPrefixChangeHandler spch = new SchemaPrefixChangeHandler(xsdSchema, xsdPrefix);
              spch.resolve();
              
              updateAllNodes(element, xsdPrefix);
              
              prefixMapping.remove(origXSDPrefix != null ? origXSDPrefix : "");
            }
            xsdSchema.setIncrementalUpdate(true);
          }
          catch (Exception localException) {}finally
          {
            xsdSchema.update();
            doc.getModel().endRecording(this);
          }
        }
      }
    }
  }
  
  protected Map createPrefixMapping(List oldList, List newList)
  {
    Map map = new Hashtable();
    
    Hashtable oldURIToPrefixTable = new Hashtable();
    for (Iterator i = oldList.iterator(); i.hasNext();)
    {
      NamespaceInfo oldInfo = (NamespaceInfo)i.next();
      oldURIToPrefixTable.put(uri, oldInfo);
    }
    for (Iterator i = newList.iterator(); i.hasNext();)
    {
      NamespaceInfo newInfo = (NamespaceInfo)i.next();
      NamespaceInfo oldInfo = (NamespaceInfo)oldURIToPrefixTable.get(uri != null ? uri : "");
      if (oldInfo == null) {
        oldInfo = (NamespaceInfo)newInfo.getProperty("oldCopy");
      }
      if (oldInfo != null)
      {
        String newPrefix = prefix != null ? prefix : "";
        String oldPrefix = prefix != null ? prefix : "";
        if (!oldPrefix.equals(newPrefix)) {
          map.put(oldPrefix, newPrefix);
        }
      }
    }
    return map;
  }
  
  private void updateAllNodes(Element element, String prefix)
  {
    element.setPrefix(prefix);
    NodeList list = element.getChildNodes();
    if (list != null) {
      for (int i = 0; i < list.getLength(); i++)
      {
        Node child = list.item(i);
        if ((child != null) && ((child instanceof Element)))
        {
          child.setPrefix(prefix);
          if (child.hasChildNodes()) {
            updateAllNodes((Element)child, prefix);
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.actions.XSDEditNamespacesAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.adapters;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IActionProvider;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IModelProxy;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObjectListener;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IModel;
import org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeGroupDefinitionAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDSchemaDirectiveAction;
import org.eclipse.xsd.XSDSchema;

public class CategoryAdapter
  extends XSDBaseAdapter
  implements IModelProxy, IActionProvider, IADTObjectListener
{
  protected String text;
  protected Image image;
  protected Object parent;
  protected int groupType;
  protected Collection children;
  protected Collection allChildren;
  XSDSchema xsdSchema;
  public static final int ATTRIBUTES = 1;
  public static final int ELEMENTS = 2;
  public static final int TYPES = 3;
  public static final int GROUPS = 5;
  public static final int DIRECTIVES = 6;
  public static final int NOTATIONS = 7;
  public static final int ATTRIBUTE_GROUPS = 8;
  public static final int IDENTITY_CONSTRAINTS = 9;
  public static final int ANNOTATIONS = 10;
  
  public CategoryAdapter(String label, Image image, Collection children, XSDSchema xsdSchema, int groupType)
  {
    text = label;
    this.image = image;
    parent = xsdSchema;
    this.xsdSchema = xsdSchema;
    target = xsdSchema;
    this.children = children;
    this.groupType = groupType;
  }
  
  public XSDSchema getXSDSchema()
  {
    return xsdSchema;
  }
  
  public int getGroupType()
  {
    return groupType;
  }
  
  public Image getImage()
  {
    return image;
  }
  
  public String getText()
  {
    return text;
  }
  
  public ITreeElement[] getChildren()
  {
    return (ITreeElement[])children.toArray(new ITreeElement[0]);
  }
  
  public ITreeElement[] getAllChildren()
  {
    return (ITreeElement[])allChildren.toArray(new ITreeElement[0]);
  }
  
  public void setChildren(Collection list)
  {
    children = list;
  }
  
  public void setAllChildren(Collection list)
  {
    allChildren = list;
  }
  
  public Object getParent(Object element)
  {
    return xsdSchema;
  }
  
  public boolean hasChildren(Object element)
  {
    return true;
  }
  
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
  
  public String[] getActions(Object object)
  {
    Collection actionIDs = new ArrayList();
    switch (groupType)
    {
    case 3: 
      actionIDs.add("org.eclipse.wst.xsd.ui.internal.editor.AddXSDComplexTypeDefinitionAction");
      actionIDs.add("org.eclipse.wst.xsd.ui.internal.editor.AddXSDSimpleTypeDefinitionAction");
      break;
    case 2: 
      actionIDs.add(AddXSDElementAction.ID);
      break;
    case 5: 
      actionIDs.add("AddXSDModelGroupDefinitionAction");
      break;
    case 1: 
      actionIDs.add(AddXSDAttributeDeclarationAction.ID);
      actionIDs.add(AddXSDAttributeGroupDefinitionAction.ID);
      break;
    case 8: 
      actionIDs.add(AddXSDAttributeGroupDefinitionAction.ID);
      break;
    case 6: 
      actionIDs.add(AddXSDSchemaDirectiveAction.INCLUDE_ID);
      actionIDs.add(AddXSDSchemaDirectiveAction.IMPORT_ID);
      actionIDs.add(AddXSDSchemaDirectiveAction.REDEFINE_ID);
    }
    actionIDs.add("org.eclipse.jface.action.Separator");
    actionIDs.add("org.eclipse.wst.xsd.ui.internal.adt.actions.ShowPropertiesViewAction");
    return (String[])actionIDs.toArray(new String[0]);
  }
  
  public void propertyChanged(Object object, String property)
  {
    if (getText().equals(property)) {
      notifyListeners(this, property);
    }
  }
  
  public List getTypes()
  {
    return null;
  }
  
  public IModel getModel()
  {
    return (IModel)XSDAdapterFactory.getInstance().adapt(xsdSchema);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.adapters.CategoryAdapter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.adapters;

import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IModel;
import org.eclipse.xsd.XSDRedefine;

public class RedefineCategoryAdapter
  extends CategoryAdapter
{
  protected XSDRedefine xsdRedefine;
  private XSDRedefineAdapter xsdRedefineAdapter;
  
  public RedefineCategoryAdapter(String label, Image image, Collection children, XSDRedefine xsdRedefine, XSDRedefineAdapter xsdRedefineAdapter, int groupType)
  {
    super(label, image, children, xsdRedefine.getSchema(), groupType);
    this.xsdRedefine = xsdRedefine;
    target = xsdRedefine;
    this.xsdRedefineAdapter = xsdRedefineAdapter;
  }
  
  public XSDRedefine getXSDRedefine()
  {
    return xsdRedefine;
  }
  
  public String[] getActions(Object object)
  {
    Collection actionIDs = new ArrayList();
    switch (groupType)
    {
    case 3: 
      actionIDs.add("org.eclipse.wst.xsd.ui.actions.RedefineComplexType");
      actionIDs.add("org.eclipse.wst.xsd.ui.actions.RedefineSimpleType");
      break;
    case 5: 
      actionIDs.add("org.eclipse.wst.xsd.ui.actions.RedefineModelGroup");
      break;
    case 1: 
    case 8: 
      actionIDs.add("org.eclipse.wst.xsd.ui.actions.RedefineAttributeGroup");
    }
    actionIDs.add("org.eclipse.jface.action.Separator");
    actionIDs.add("org.eclipse.wst.xsd.ui.internal.adt.actions.ShowPropertiesViewAction");
    return (String[])actionIDs.toArray(new String[0]);
  }
  
  public IModel getModel()
  {
    return (IModel)XSDAdapterFactory.getInstance().adapt(xsdRedefine.getSchema());
  }
  
  public XSDRedefineAdapter getXsdRedefineAdapter()
  {
    return xsdRedefineAdapter;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.xsd.ui.internal.adapters.RedefineCategoryAdapter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.xsd.ui.internal.adapters;

import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDEnumerationFacet;
import org.eclipse.xsd.XS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd