Search in sources :

Example 1 with XSDSchemaDirectiveAdapter

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());
                        }
                    }
                }
            }
        }
    }
}
Also used : XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDImportImpl(org.eclipse.xsd.impl.XSDImportImpl) IGraphElement(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement) LocationRequest(org.eclipse.gef.requests.LocationRequest) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with XSDSchemaDirectiveAdapter

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));
        }
    }
}
Also used : XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) BaseCommand(org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) AddXSDRedefineCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDRedefineCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDSchema(org.eclipse.xsd.XSDSchema) AddXSDIncludeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDIncludeCommand) AddXSDImportCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDImportCommand)

Example 3 with XSDSchemaDirectiveAdapter

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);
        }
    }
}
Also used : XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) IPath(org.eclipse.core.runtime.IPath) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDImportImpl(org.eclipse.xsd.impl.XSDImportImpl) XSDFeature(org.eclipse.xsd.XSDFeature) XSDFileEditorInput(org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput) XSDFileEditorInput(org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IEditorInput(org.eclipse.ui.IEditorInput) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDSchemaDirectiveAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)2 XSDSchema (org.eclipse.xsd.XSDSchema)2 XSDSchemaDirective (org.eclipse.xsd.XSDSchemaDirective)2 XSDImportImpl (org.eclipse.xsd.impl.XSDImportImpl)2 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 Point (org.eclipse.draw2d.geometry.Point)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 LocationRequest (org.eclipse.gef.requests.LocationRequest)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 IGraphElement (org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement)1