use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDHyperlinkDetector method createHyperlink.
/**
* Creates a hyperlink based on the selected node. Derived classes should
* override.
*
* @param document the source document.
* @param node the node under the cursor.
* @param region the text region to use to create the hyperlink.
* @return a new IHyperlink for the node or null if one cannot be created.
*/
protected IHyperlink createHyperlink(IDocument document, IDOMNode node, IRegion region) {
XSDSchema xsdSchema = getXSDSchema(document);
if (xsdSchema == null) {
return null;
}
XSDConcreteComponent targetComponent = getTargetXSDComponent(xsdSchema, node);
if (targetComponent != null) {
IRegion nodeRegion = getHyperlinkRegion(node);
return new XSDHyperlink(nodeRegion, targetComponent);
}
return null;
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class AddXSDAttributeDeclarationAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
if (selection instanceof XSDAttributeDeclaration) {
selection = ((XSDAttributeDeclaration) selection).getContainer();
}
}
AddXSDAttributeDeclarationCommand command = null;
if (selection instanceof XSDComplexTypeDefinition) {
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDAttributeUse) {
XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection;
XSDConcreteComponent parent = null;
XSDComplexTypeDefinition ct = null;
XSDAttributeGroupDefinition group = null;
for (parent = xsdAttributeUse.getContainer(); parent != null; ) {
if (parent instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) parent;
break;
} else if (parent instanceof XSDAttributeGroupDefinition) {
group = (XSDAttributeGroupDefinition) parent;
break;
}
parent = parent.getContainer();
}
if (ct != null) {
XSDAttributeUse sel = (XSDAttributeUse) selection;
int index = ct.getAttributeContents().indexOf(sel);
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (group != null) {
XSDAttributeUse sel = (XSDAttributeUse) selection;
int index = group.eContents().indexOf(sel);
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
}
} else if (selection instanceof XSDAttributeGroupDefinition) {
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDSchema) {
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema) selection);
getCommandStack().execute(command);
}
if (command != null) {
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupDefinitionAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
XSDConcreteComponent xsdConcreteComponent = null;
if (selection instanceof XSDBaseAdapter) {
xsdConcreteComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget();
}
if (xsdConcreteComponent != null) {
AddXSDModelGroupDefinitionCommand command = new AddXSDModelGroupDefinitionCommand(getText(), xsdConcreteComponent, isReference);
getCommandStack().execute(command);
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class AddXSDElementAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
AddXSDElementCommand command = null;
if (selection instanceof XSDComplexTypeDefinition) {
command = new AddXSDElementCommand(getText(), (XSDComplexTypeDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDModelGroupDefinition) {
command = new AddXSDElementCommand(getText(), (XSDModelGroupDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDSchema) {
command = new AddXSDElementCommand(getText(), (XSDSchema) selection);
getCommandStack().execute(command);
} else if (selection instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) selection;
XSDConcreteComponent component = modelGroup.getContainer();
XSDComplexTypeDefinition ct = null;
while (component != null) {
if (component instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) component;
break;
}
component = component.getContainer();
}
if (ct != null) {
command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection, ct);
} else {
command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection);
}
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDElementDeclaration || selection instanceof XSDAttributeUse) {
XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent) selection;
XSDConcreteComponent parent = null;
XSDComplexTypeDefinition ct = null;
XSDModelGroupDefinition group = null;
XSDModelGroupImpl ctGroup = null;
for (parent = xsdConcreteComponent.getContainer(); parent != null; ) {
if (parent instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) parent;
break;
} else if (parent instanceof XSDModelGroupDefinition) {
group = (XSDModelGroupDefinition) parent;
break;
} else if (parent instanceof XSDModelGroupImpl) {
ctGroup = (XSDModelGroupImpl) parent;
break;
}
parent = parent.getContainer();
}
if (ct != null) {
command = new AddXSDElementCommand(getText(), ct);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (ctGroup != null) {
XSDElementDeclaration sel = (XSDElementDeclaration) selection;
int index = ctGroup.getContents().indexOf(sel.eContainer());
command = new AddXSDElementCommand(getText(), ctGroup, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (group != null) {
command = new AddXSDElementCommand(getText(), group);
command.setReference(isReference);
getCommandStack().execute(command);
}
}
if (command != null) {
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class OpenInNewEditor method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = null;
IEditorInput editorInput = null;
if (workbenchWindow != null) {
page = workbenchWindow.getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
if (activeEditor != null) {
editorInput = activeEditor.getEditorInput();
}
}
if (selection instanceof XSDBaseAdapter) {
XSDBaseAdapter xsdAdapter = (XSDBaseAdapter) selection;
XSDConcreteComponent fComponent = (XSDConcreteComponent) xsdAdapter.getTarget();
XSDSchema schema = fComponent.getSchema();
boolean isReference = false;
if (fComponent instanceof XSDFeature) {
isReference = ((XSDFeature) fComponent).isFeatureReference();
fComponent = ((XSDFeature) fComponent).getResolvedFeature();
}
String schemaLocation = null;
IPath schemaPath = null;
IFile schemaFile = null;
// Special case any imports/includes
if (selection instanceof XSDSchemaDirectiveAdapter) {
XSDSchemaDirective dir = (XSDSchemaDirective) ((XSDSchemaDirectiveAdapter) selection).getTarget();
// force load of imported schema
if (dir instanceof XSDImportImpl) {
((XSDImportImpl) dir).importSchema();
}
if (dir.getResolvedSchema() != null) {
schemaLocation = URIHelper.removePlatformResourceProtocol(dir.getResolvedSchema().getSchemaLocation());
schemaPath = new Path(schemaLocation);
schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
schema = dir.getResolvedSchema();
fComponent = dir.getResolvedSchema();
}
} else // Handle any other external components
if (fComponent.getSchema() != null && fComponent.eContainer() instanceof XSDSchema || fComponent.eContainer() instanceof XSDRedefine || isReference) {
schemaLocation = URIHelper.removePlatformResourceProtocol(fComponent.getSchema().getSchemaLocation());
schemaPath = new Path(schemaLocation);
schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
try {
XSDSchema xsdSchema = (XSDSchema) getWorkbenchPart().getAdapter(XSDSchema.class);
if (fComponent.getSchema() == xsdSchema) {
IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart instanceof InternalXSDMultiPageEditor) {
((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(fComponent);
}
return;
}
} catch (Exception e) {
}
}
// If the schemaFile exists in the workspace
if (page != null && schemaFile != null && schemaFile.exists()) {
try {
// Get the current editor's schema
XSDSchema xsdSchema = (XSDSchema) getWorkbenchPart().getAdapter(XSDSchema.class);
IEditorPart editorPart = null;
// are in the same resource file....hence multiple schemas in the same file.
if (xsdSchema != null && fComponent.getRootContainer().eResource() == xsdSchema.eResource() && xsdSchema != schema) {
String editorName = null;
XSDFileEditorInput xsdFileEditorInput = new XSDFileEditorInput(schemaFile, fComponent.getSchema());
// Try to use the same editor name as the current one
if (editorInput != null) {
editorName = editorInput.getName();
xsdFileEditorInput.setEditorName(editorName);
}
editorPart = getExistingEditorForInlineSchema(page, schemaFile, schema);
if (editorPart == null) {
editorPart = page.openEditor(xsdFileEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
}
} else {
editorPart = page.openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.EDITOR_ID);
}
if (editorPart instanceof InternalXSDMultiPageEditor) {
((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(fComponent);
}
} catch (Exception e) {
}
} else {
// open the xsd externally
if (schemaLocation != null)
openExternalFiles(page, schemaLocation, fComponent);
}
}
}
Aggregations