Search in sources :

Example 1 with IModel

use of org.eclipse.wst.xsd.ui.internal.adt.facade.IModel in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method editorModeChanged.

public void editorModeChanged(EditorMode newEditorMode) {
    // if (isInitializing)
    // return;
    EditPartFactory editPartFactory = newEditorMode.getEditPartFactory();
    if (editPartFactory != null) {
        graphicalViewer.setEditPartFactory(editPartFactory);
        if (graphicalViewer instanceof DesignViewGraphicalViewer) {
            DesignViewGraphicalViewer viewer = (DesignViewGraphicalViewer) graphicalViewer;
            IADTObject input = viewer.getInput();
            viewer.setInput(null);
            // viewer.getRootEditPart().refresh();
            // viewer.getRootEditPart().getContents().refresh();
            viewer.setInput(input);
            floatingToolbar.setEditPartFactory(editPartFactory);
            floatingToolbar.setModel(getModel());
            floatingToolbar.refresh(!(input instanceof IModel));
            Control control = graphicalViewer.getControl();
            if (control instanceof Composite) {
                Composite parent = ((Composite) control).getParent();
                parent.layout();
            }
        }
    }
    IContentProvider provider = newEditorMode.getOutlineProvider();
    if (provider != null) {
        ADTContentOutlinePage outline = (ADTContentOutlinePage) getContentOutlinePage();
        if (outline != null) {
            TreeViewer treeViewer = outline.getTreeViewer();
            if (treeViewer != null) {
                outline.getTreeViewer().setContentProvider(provider);
                outline.getTreeViewer().refresh();
            }
        }
    }
}
Also used : DesignViewGraphicalViewer(org.eclipse.wst.xsd.ui.internal.adt.design.DesignViewGraphicalViewer) IModel(org.eclipse.wst.xsd.ui.internal.adt.facade.IModel) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) TreeViewer(org.eclipse.jface.viewers.TreeViewer) EditPartFactory(org.eclipse.gef.EditPartFactory) ADTContentOutlinePage(org.eclipse.wst.xsd.ui.internal.adt.outline.ADTContentOutlinePage)

Example 2 with IModel

use of org.eclipse.wst.xsd.ui.internal.adt.facade.IModel in project webtools.sourceediting by eclipse.

the class DeleteAction method run.

public void run() {
    for (Iterator i = ((IStructuredSelection) getSelection()).iterator(); i.hasNext(); ) {
        Object selection = i.next();
        Command command = null;
        boolean doSetInput = false;
        boolean doSetModelAsInput = false;
        IADTObject topLevelContainer = null;
        IModel model = null;
        if (selection instanceof IGraphElement) {
            IGraphElement xsdObj = (IGraphElement) selection;
            if (xsdObj instanceof XSDBaseAdapter) {
                XSDBaseAdapter baseAdapter = (XSDBaseAdapter) xsdObj;
                // is null and the read only check cannot be completed
                if (baseAdapter == null || baseAdapter.isReadOnly()) {
                    continue;
                }
                topLevelContainer = xsdObj.getTopContainer();
                if (topLevelContainer == selection) {
                    doSetInput = true;
                    doSetModelAsInput = true;
                }
                command = xsdObj.getDeleteCommand();
                model = xsdObj.getModel();
            }
        }
        if (command != null) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            if (workbench != null) {
                IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                if (workbenchWindow != null && workbenchWindow.getActivePage() != null) {
                    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                    if (editorPart != null) {
                        Object viewer = editorPart.getAdapter(GraphicalViewer.class);
                        if (viewer instanceof DesignViewGraphicalViewer) {
                            Object input = ((DesignViewGraphicalViewer) viewer).getInput();
                            if (input != selection) {
                                // Bug 86218 : Don't switch to top level view if the object we're deleting
                                // is not the input to the viewer
                                doSetInput = false;
                            }
                        }
                    }
                }
            }
            command.execute();
            if (doSetInput) {
                if (model != null && doSetModelAsInput)
                    provider.setSelection(new StructuredSelection(model));
                else if (topLevelContainer != null && !doSetModelAsInput)
                    provider.setSelection(new StructuredSelection(topLevelContainer));
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IModel(org.eclipse.wst.xsd.ui.internal.adt.facade.IModel) IGraphElement(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) DesignViewGraphicalViewer(org.eclipse.wst.xsd.ui.internal.adt.design.DesignViewGraphicalViewer) Command(org.eclipse.gef.commands.Command) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) Iterator(java.util.Iterator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)

Example 3 with IModel

use of org.eclipse.wst.xsd.ui.internal.adt.facade.IModel in project webtools.sourceediting by eclipse.

the class XSDSchemaDirectiveAdapter method getModel.

public IModel getModel() {
    XSDSchema object = ((XSDSchemaDirective) target).getSchema();
    Adapter adapter = XSDAdapterFactory.getInstance().adapt(object);
    return (IModel) adapter;
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) IModel(org.eclipse.wst.xsd.ui.internal.adt.facade.IModel) Adapter(org.eclipse.emf.common.notify.Adapter) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 4 with IModel

use of org.eclipse.wst.xsd.ui.internal.adt.facade.IModel in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method buildModel.

public IModel buildModel() {
    try {
        IEditorInput editorInput = getEditorInput();
        // If the input schema is from the WSDL Editor, then use that inline schema
        if (editorInput instanceof IADTEditorInput) {
            xsdSchema = ((IADTEditorInput) editorInput).getSchema();
            if (xsdSchema != null)
                model = (IModel) XSDAdapterFactory.getInstance().adapt(xsdSchema);
        }
        Document document = null;
        IDocument doc = structuredTextEditor.getDocumentProvider().getDocument(getEditorInput());
        if (doc instanceof IStructuredDocument) {
            IStructuredModel model = null;
            try {
                // TODO: for StorageEditorInputs, should be forRead
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(doc);
                if (model == null) {
                    model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) doc);
                }
                document = ((IDOMModel) model).getDocument();
            } finally {
                if (model != null) {
                    model.releaseFromEdit();
                }
            }
        }
        Assert.isNotNull(document);
        if (model != null)
            return model;
        xsdSchema = XSDModelAdapter.lookupOrCreateSchema(document);
        model = (IModel) XSDAdapterFactory.getInstance().adapt(xsdSchema);
    } catch (Exception e) {
    }
    // }
    return model;
}
Also used : IModel(org.eclipse.wst.xsd.ui.internal.adt.facade.IModel) IADTEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.IADTEditorInput) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with IModel

use of org.eclipse.wst.xsd.ui.internal.adt.facade.IModel in project webtools.sourceediting by eclipse.

the class DesignViewGraphicalViewer method selectionChanged.

// this method is called when something changes in the selection manager
// (e.g. a selection occured from another view)
public void selectionChanged(SelectionChangedEvent event) {
    Object selectedObject = null;
    ISelection eventSelection = event.getSelection();
    if (eventSelection instanceof StructuredSelection) {
        selectedObject = ((StructuredSelection) eventSelection).getFirstElement();
    }
    // if (event.getSource() instanceof ADTContentOutlinePage)
    if (selectedObject != null) {
        if (event.getSource() != internalSelectionProvider) {
            if (selectedObject instanceof IStructure) {
                if (((getInput() instanceof IModel) && (event.getSource() instanceof ADTContentOutlinePage)) || (!(getInput() instanceof IModel))) {
                    if ((selectedObject instanceof IGraphElement) && ((IGraphElement) selectedObject).isFocusAllowed()) {
                        if (!(event.getSource() instanceof org.eclipse.jface.viewers.IPostSelectionProvider)) {
                            setInputAndMarkLocation((IStructure) selectedObject);
                        }
                    }
                }
            } else if (selectedObject instanceof IGraphElement) {
                if (((IGraphElement) selectedObject).isFocusAllowed() && ((event.getSource() instanceof ADTContentOutlinePage))) {
                    setInputAndMarkLocation((IADTObject) selectedObject);
                } else if (!((IGraphElement) selectedObject).isFocusAllowed()) {
                    // We encountered an object that is not a valid input to the graph viewer
                    // Now find the top container that can be a valid input
                    IADTObject obj = ((IGraphElement) selectedObject).getTopContainer();
                    if (event.getSource() instanceof ADTContentOutlinePage) {
                        // change the inputs
                        if (// Don't change inputs if the obj is already the input
                        obj != null && getInput() != obj)
                            setInputAndMarkLocation(obj);
                    } else if (event.getSource() instanceof CommonSelectionManager) {
                        // otherwise, inputs will change unexpectedly!!
                        if (getInput() instanceof IModel) {
                            if (obj != null)
                                setInput(obj);
                        }
                    } else if (event.getSource() instanceof org.eclipse.jface.viewers.IPostSelectionProvider) {
                        // of anonymous types
                        if (obj != null)
                            setInput(obj);
                    } else {
                        if (obj != null && getInput() instanceof IModel)
                            setInputAndMarkLocation(obj);
                    }
                }
                if (selectedObject instanceof IField) {
                    IField field = (IField) selectedObject;
                    if ((!field.isGlobal() && getInput() instanceof IModel) || (!field.isGlobal() && !(event.getSource() instanceof CommonSelectionManager))) {
                        IADTObject obj = ((IGraphElement) selectedObject).getTopContainer();
                        if (obj != null)
                            setInputAndMarkLocation(obj);
                    } else if (field.isGlobal() && !(getInput() instanceof IModel)) {
                        if (event.getSource() instanceof org.eclipse.jface.viewers.IPostSelectionProvider)
                            setInput(field);
                        else
                            setInputAndMarkLocation(field);
                    }
                }
            } else if (selectedObject instanceof IField) {
                IField field = (IField) selectedObject;
                if ((field.isGlobal() && (getInput() instanceof IModel) && (event.getSource() instanceof ADTContentOutlinePage)) || ((field.isGlobal() && !(getInput() instanceof IModel)))) {
                    setInputAndMarkLocation(field);
                }
            } else if (selectedObject instanceof IModelProxy) {
                IModelProxy adapter = (IModelProxy) selectedObject;
                if (selectedObject instanceof RedefineCategoryAdapter) {
                    RedefineCategoryAdapter selectionAdapter = (RedefineCategoryAdapter) selectedObject;
                    XSDRedefineAdapter selectionParentAdapter = selectionAdapter.getXsdRedefineAdapter();
                    setInputAndMarkLocation(selectionParentAdapter);
                } else if (getInput() != adapter.getModel())
                    setInput(adapter.getModel());
            } else if (selectedObject instanceof IModel) {
                if (getInput() != selectedObject)
                    setInput((IModel) selectedObject);
            }
            EditPart editPart = getEditPart(getRootEditPart(), selectedObject);
            if (editPart != null) {
                setSelection(new StructuredSelection(editPart));
                setFocus(editPart);
            }
        }
    }
}
Also used : IModel(org.eclipse.wst.xsd.ui.internal.adt.facade.IModel) IModelProxy(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IModelProxy) IGraphElement(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RootContentEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.RootContentEditPart) IHolderEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.IHolderEditPart) StructureEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.StructureEditPart) EditPart(org.eclipse.gef.EditPart) CommonSelectionManager(org.eclipse.wst.xsd.ui.internal.adt.editor.CommonSelectionManager) IStructure(org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure) IField(org.eclipse.wst.xsd.ui.internal.adt.facade.IField) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) RedefineCategoryAdapter(org.eclipse.wst.xsd.ui.internal.adapters.RedefineCategoryAdapter) ISelection(org.eclipse.jface.viewers.ISelection) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) ADTContentOutlinePage(org.eclipse.wst.xsd.ui.internal.adt.outline.ADTContentOutlinePage) XSDRedefineAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDRedefineAdapter)

Aggregations

IModel (org.eclipse.wst.xsd.ui.internal.adt.facade.IModel)7 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)4 IGraphElement (org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement)3 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 DesignViewGraphicalViewer (org.eclipse.wst.xsd.ui.internal.adt.design.DesignViewGraphicalViewer)2 IField (org.eclipse.wst.xsd.ui.internal.adt.facade.IField)2 IStructure (org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure)2 ADTContentOutlinePage (org.eclipse.wst.xsd.ui.internal.adt.outline.ADTContentOutlinePage)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 EditPart (org.eclipse.gef.EditPart)1 EditPartFactory (org.eclipse.gef.EditPartFactory)1 Command (org.eclipse.gef.commands.Command)1 IDocument (org.eclipse.jface.text.IDocument)1 IContentProvider (org.eclipse.jface.viewers.IContentProvider)1 ISelection (org.eclipse.jface.viewers.ISelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1