Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java')
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java322
1 files changed, 0 insertions, 322 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java
deleted file mode 100644
index 82de07f482..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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.ui.internal.util;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.wst.sse.core.IndexedRegion;
-import org.eclipse.wst.xml.uriresolver.util.URIHelper;
-import org.eclipse.wst.xsd.ui.internal.XSDEditor;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-import org.eclipse.wst.xsd.ui.internal.XSDTextEditor;
-import org.eclipse.xsd.XSDAttributeDeclaration;
-import org.eclipse.xsd.XSDAttributeGroupDefinition;
-import org.eclipse.xsd.XSDConcreteComponent;
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.XSDIdentityConstraintDefinition;
-import org.eclipse.xsd.XSDModelGroupDefinition;
-import org.eclipse.xsd.XSDNamedComponent;
-import org.eclipse.xsd.XSDSchema;
-import org.eclipse.xsd.XSDSchemaDirective;
-import org.eclipse.xsd.XSDSimpleTypeDefinition;
-import org.eclipse.xsd.XSDTypeDefinition;
-import org.eclipse.xsd.util.XSDConstants;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Node;
-
-
-public class OpenOnSelectionHelper
-{
-
- protected XSDTextEditor textEditor;
-
- /**
- * Constructor for OpenOnSelectionHelper.
- */
- public OpenOnSelectionHelper(XSDTextEditor textEditor)
- {
- this.textEditor = textEditor;
- }
-
- boolean lastResult;
-
- public static void openXSDEditor(String schemaLocation)
- {
- IPath schemaPath = new Path(schemaLocation);
-
- final IFile schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
-
- Display.getDefault().syncExec(new Runnable()
- {
- /**
- * @see java.lang.Runnable#run()
- */
- public void run()
- {
- final IWorkbenchWindow workbenchWindow = XSDEditorPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow();
- if (workbenchWindow != null)
- {
- try
- {
- IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.XSD_EDITOR_ID);
- }
- catch (PartInitException initEx)
- {
- initEx.printStackTrace();
-// XSDEditorPlugin.getPlugin().getMsgLogger().write(initEx);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- });
- }
-
- protected boolean revealObject(final XSDConcreteComponent component)
- {
- if (component.getRootContainer().equals(textEditor.getXSDSchema()))
- {
- Node element = component.getElement();
- if (element instanceof IndexedRegion)
- {
- IndexedRegion indexNode = (IndexedRegion) element;
- textEditor.getTextViewer().setRangeIndication(indexNode.getStartOffset(), indexNode.getEndOffset() - indexNode.getStartOffset(), true);
- return true;
- }
- return false;
- }
- else
- {
- lastResult = false;
- if (component.getSchema() != null)
- {
- String schemaLocation = URIHelper.removePlatformResourceProtocol(component.getSchema().getSchemaLocation());
- IPath schemaPath = new Path(schemaLocation);
- final IFile schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
- Display.getDefault().syncExec(new Runnable()
- {
- /**
- * @see java.lang.Runnable#run()
- */
- public void run()
- {
- final IWorkbenchWindow workbenchWindow = XSDEditorPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow();
- if (workbenchWindow != null)
- {
- try
- {
- IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), textEditor.getXSDEditor().getEditorSite().getId());
- if (editorPart instanceof XSDEditor)
- {
- ((XSDEditor)editorPart).openOnGlobalReference(component);
- lastResult = true;
- }
- }
- catch (PartInitException initEx)
- {
-// XSDEditorPlugin.getPlugin().getMsgLogger().write(initEx);
- }
- }
- }
- });
- }
- return lastResult;
- }
- }
-
- public void openOnGlobalReference(XSDConcreteComponent comp)
- {
- XSDSchema schema = textEditor.getXSDSchema();
- String name = null;
- if (comp instanceof XSDNamedComponent)
- {
- name = ((XSDNamedComponent) comp).getName();
- }
-
- if (schema == null || name == null)
- {
- return;
- }
-
- List objects = null;
- if (comp instanceof XSDElementDeclaration)
- {
- objects = schema.getElementDeclarations();
- }
- else if (comp instanceof XSDTypeDefinition)
- {
- objects = schema.getTypeDefinitions();
- }
-
- if (objects != null)
- {
- for (Iterator iter = objects.iterator(); iter.hasNext();)
- {
- XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
-
- if (namedComp.getName().equals(name))
- {
- revealObject(namedComp);
- }
- }
- }
- }
-
- public boolean openOnSelection()
- {
- List selectedNodes = textEditor.getViewerSelectionManager().getSelectedNodes();
-
- if (!selectedNodes.isEmpty())
- {
- for (Iterator i = selectedNodes.iterator(); i.hasNext();)
- {
- Object obj = i.next();
- XSDSchema xsdSchema = textEditor.getXSDSchema();
- if (xsdSchema != null)
- {
- XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node)obj);
- XSDConcreteComponent objectToReveal = null;
-
- if (xsdComp instanceof XSDElementDeclaration)
- {
- XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
- if (elementDecl.isElementDeclarationReference())
- {
- objectToReveal = elementDecl.getResolvedElementDeclaration();
- }
- else
- {
- XSDConcreteComponent typeDef = null;
- if (elementDecl.getAnonymousTypeDefinition() == null)
- {
- typeDef = elementDecl.getTypeDefinition();
- }
-
- XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
-
- if (typeDef != null && subGroupAffiliation != null)
- {
- // we have 2 things we can navigate to, if the cursor is anywhere on the substitution attribute
- // then jump to that, otherwise just go to the typeDef.
- if (obj instanceof Attr && ((Attr)obj).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE))
- {
- objectToReveal = subGroupAffiliation;
- }
- else
- {
- // try to reveal the type now. On success, then we return true.
- // if we fail, set the substitution group as the object to reveal as a backup plan.
- if (revealObject(typeDef))
- {
- return true;
- }
- else
- {
- objectToReveal = subGroupAffiliation;
- }
- }
- }
- else
- {
- // one or more of these is null. If the typeDef is non-null, use it. Otherwise
- // try and use the substitution group
- objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
- }
- }
- }
- else if (xsdComp instanceof XSDModelGroupDefinition)
- {
- XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
- if (elementDecl.isModelGroupDefinitionReference())
- {
- objectToReveal = elementDecl.getResolvedModelGroupDefinition();
- }
- }
- else if (xsdComp instanceof XSDAttributeDeclaration)
- {
- XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
- if (attrDecl.isAttributeDeclarationReference())
- {
- objectToReveal = attrDecl.getResolvedAttributeDeclaration();
- }
- else if (attrDecl.getAnonymousTypeDefinition() == null)
- {
- objectToReveal = attrDecl.getTypeDefinition();
- }
- }
- else if (xsdComp instanceof XSDAttributeGroupDefinition)
- {
- XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
- if (attrGroupDef.isAttributeGroupDefinitionReference())
- {
- objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
- }
- }
- else if (xsdComp instanceof XSDIdentityConstraintDefinition)
- {
- XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
- if (idConstraintDef.getReferencedKey() != null)
- {
- objectToReveal = idConstraintDef.getReferencedKey();
- }
- }
- else if (xsdComp instanceof XSDSimpleTypeDefinition)
- {
- XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
- objectToReveal = typeDef.getItemTypeDefinition();
- if (objectToReveal == null)
- {
- // if itemType attribute is not set, then check for memberType
- List memberTypes = typeDef.getMemberTypeDefinitions();
- if (memberTypes != null && memberTypes.size() > 0)
- {
- objectToReveal = (XSDConcreteComponent)memberTypes.get(0);
- }
- }
- }
- else if (xsdComp instanceof XSDTypeDefinition)
- {
- XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
- objectToReveal = typeDef.getBaseType();
- }
- else if (xsdComp instanceof XSDSchemaDirective)
- {
- XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
-// String schemaLocation = URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
-// openXSDEditor(schemaLocation);
-// return false;
- objectToReveal = directive.getResolvedSchema();
- }
-
- // now reveal the object if this isn't null
- if (objectToReveal != null)
- {
- return revealObject(objectToReveal);
- }
- }
- }
- }
- return false;
- }
-
-}

Back to the top