use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter in project webtools.sourceediting by eclipse.
the class TopLevelComponentEditPart method performRequest.
public void performRequest(Request request) {
// Do not open on or set focus on direct edit type
if (request.getType() == RequestConstants.REQ_OPEN) {
Object model = getModel();
if (model instanceof IGraphElement) {
if (((IGraphElement) model).isFocusAllowed()) {
if (request instanceof LocationRequest) {
LocationRequest locationRequest = (LocationRequest) request;
Point p = locationRequest.getLocation();
if (hitTest(labelHolder, p)) {
performDrillDownAction();
}
}
}
} else if (model instanceof XSDSchemaDirectiveAdapter) {
if (request instanceof LocationRequest) {
LocationRequest locationRequest = (LocationRequest) request;
Point p = locationRequest.getLocation();
if (hitTest(labelHolder, p)) {
XSDSchemaDirective dir = (XSDSchemaDirective) ((XSDSchemaDirectiveAdapter) model).getTarget();
String schemaLocation = "";
// force load of imported schema
if (dir instanceof XSDImportImpl) {
((XSDImportImpl) dir).importSchema();
}
if (dir.getResolvedSchema() != null) {
schemaLocation = URIHelper.removePlatformResourceProtocol(dir.getResolvedSchema().getSchemaLocation());
if (schemaLocation != null) {
OpenOnSelectionHelper.openXSDEditor(dir.getResolvedSchema());
}
}
}
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter in project webtools.sourceediting by eclipse.
the class AddXSDSchemaDirectiveAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
BaseCommand command = null;
if (selection instanceof XSDSchema) {
if (INCLUDE_ID.equals(getId())) {
command = new AddXSDIncludeCommand(label, (XSDSchema) selection);
} else if (IMPORT_ID.equals(getId())) {
command = new AddXSDImportCommand(label, (XSDSchema) selection);
} else if (REDEFINE_ID.equals(getId())) {
command = new AddXSDRedefineCommand(label, (XSDSchema) selection);
}
getCommandStack().execute(command);
}
if (command != null) {
Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent());
if (adapter != null) {
provider.setSelection(new StructuredSelection(adapter));
// Automatically open the schema location dialog if the preference is enabled
if (XSDEditorPlugin.getDefault().getAutomaticallyOpenSchemaLocationDialogSetting()) {
XSDSchemaDirectiveAdapter xsdSchemaDirectiveAdapter = null;
if (adapter instanceof XSDSchemaDirectiveAdapter) {
xsdSchemaDirectiveAdapter = (XSDSchemaDirectiveAdapter) adapter;
}
XSDDirectivesSchemaLocationUpdater.updateSchemaLocation((XSDSchema) selection, xsdSchemaDirectiveAdapter.getTarget(), (command instanceof AddXSDIncludeCommand || command instanceof AddXSDRedefineCommand));
}
// The graphical view may deselect, so select again
provider.setSelection(new StructuredSelection(adapter));
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter 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