use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter 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.wst.xsd.ui.internal.adapters.XSDBaseAdapter 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.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class AddXSDSimpleTypeDefinitionAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
if (selection instanceof XSDSchema) {
AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, (XSDSchema) selection);
getCommandStack().execute(command);
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter 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);
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.
the class AddXSDAnyElementAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
XSDModelGroup modelGroup = getModelGroup(selection);
AddXSDAnyElementCommand command = new AddXSDAnyElementCommand(getText(), modelGroup);
if (selection instanceof XSDComplexTypeDefinition) {
command.setComplexType((XSDComplexTypeDefinition) selection);
}
command.setDoCreateModelGroupForComplexType(modelGroup == null);
getCommandStack().execute(command);
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
Aggregations