Search in sources :

Example 6 with IEditingDomainProvider

use of org.eclipse.emf.edit.domain.IEditingDomainProvider in project statecharts by Yakindu.

the class ResourceUnloadingTool method unloadEditorInput.

public static void unloadEditorInput(ResourceSet resourceSet, IEditorInput editorInput) {
    final EList<Resource> resources = resourceSet.getResources();
    final List<Resource> resourcesToUnload = new ArrayList<Resource>(resources);
    IEditorReference[] editorReferences;
    try {
        editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    } catch (final NullPointerException exc) {
        // see bug http://code.google.com/p/gmftools/issues/detail?id=9
        return;
    }
    for (final IEditorReference openEditorReference : editorReferences) {
        try {
            final IEditorInput openEditorInput = openEditorReference.getEditorInput();
            if (openEditorInput != editorInput) {
                final IEditorPart openEditor = openEditorReference.getEditor(false);
                if (openEditor instanceof IEditingDomainProvider) {
                    final IEditingDomainProvider openDiagramEditor = (IEditingDomainProvider) openEditor;
                    final ResourceSet diagramResourceSet = openDiagramEditor.getEditingDomain().getResourceSet();
                    if (diagramResourceSet == resourceSet) {
                        final Resource diagramResource = getDiagramResource(diagramResourceSet, openEditorInput);
                        resourcesToUnload.remove(diagramResource);
                        final Collection<?> imports = EMFCoreUtil.getImports(diagramResource);
                        resourcesToUnload.removeAll(imports);
                    }
                }
            }
        } catch (final Exception exc) {
            exc.printStackTrace();
        }
    }
    for (final Resource resourceToUnload : resourcesToUnload) {
        try {
            resourceToUnload.unload();
            resources.remove(resourceToUnload);
        } catch (final Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEditorReference(org.eclipse.ui.IEditorReference) IEditorInput(org.eclipse.ui.IEditorInput) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) IEditingDomainProvider(org.eclipse.emf.edit.domain.IEditingDomainProvider)

Example 7 with IEditingDomainProvider

use of org.eclipse.emf.edit.domain.IEditingDomainProvider in project metalib by softlang.

the class FsmlActionBarContributor method selectionChanged.

/**
 * This implements {@link org.eclipse.jface.viewers.ISelectionChangedListener},
 * handling {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings
 * that can be added to the selected object and updating the menus accordingly.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event) {
    // 
    if (createChildMenuManager != null) {
        depopulateManager(createChildMenuManager, createChildActions);
    }
    if (createSiblingMenuManager != null) {
        depopulateManager(createSiblingMenuManager, createSiblingActions);
    }
    // Query the new selection for appropriate new child/sibling descriptors
    // 
    Collection<?> newChildDescriptors = null;
    Collection<?> newSiblingDescriptors = null;
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
        Object object = ((IStructuredSelection) selection).getFirstElement();
        EditingDomain domain = ((IEditingDomainProvider) activeEditorPart).getEditingDomain();
        newChildDescriptors = domain.getNewChildDescriptors(object, null);
        newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
    }
    // Generate actions for selection; populate and redraw the menus.
    // 
    createChildActions = generateCreateChildActions(newChildDescriptors, selection);
    createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection);
    if (createChildMenuManager != null) {
        populateManager(createChildMenuManager, createChildActions, null);
        createChildMenuManager.update(true);
    }
    if (createSiblingMenuManager != null) {
        populateManager(createSiblingMenuManager, createSiblingActions, null);
        createSiblingMenuManager.update(true);
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) IEditingDomainProvider(org.eclipse.emf.edit.domain.IEditingDomainProvider)

Example 8 with IEditingDomainProvider

use of org.eclipse.emf.edit.domain.IEditingDomainProvider in project statecharts by Yakindu.

the class StatechartDiagramGlobalActionHandler method getEditingDomain.

/**
 * Copied from
 * DiagramGlobalActionHandler.getEditingDomain(IDiagramWorkbenchPart) because it is private.
 */
private TransactionalEditingDomain getEditingDomain(IDiagramWorkbenchPart part) {
    TransactionalEditingDomain result = null;
    IEditingDomainProvider provider = (IEditingDomainProvider) part.getAdapter(IEditingDomainProvider.class);
    if (provider != null) {
        EditingDomain domain = provider.getEditingDomain();
        if (domain != null && domain instanceof TransactionalEditingDomain) {
            result = (TransactionalEditingDomain) domain;
        }
    }
    return result;
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) IEditingDomainProvider(org.eclipse.emf.edit.domain.IEditingDomainProvider)

Example 9 with IEditingDomainProvider

use of org.eclipse.emf.edit.domain.IEditingDomainProvider in project InformationSystem by ObeoNetwork.

the class StateMachineActionBarContributor method selectionChanged.

/**
 * This implements {@link org.eclipse.jface.viewers.ISelectionChangedListener},
 * handling {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings
 * that can be added to the selected object and updating the menus accordingly.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event) {
    // 
    if (createChildMenuManager != null) {
        depopulateManager(createChildMenuManager, createChildActions);
    }
    if (createSiblingMenuManager != null) {
        depopulateManager(createSiblingMenuManager, createSiblingActions);
    }
    // Query the new selection for appropriate new child/sibling descriptors
    // 
    Collection<?> newChildDescriptors = null;
    Collection<?> newSiblingDescriptors = null;
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
        Object object = ((IStructuredSelection) selection).getFirstElement();
        EditingDomain domain = ((IEditingDomainProvider) activeEditorPart).getEditingDomain();
        newChildDescriptors = domain.getNewChildDescriptors(object, null);
        newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
    }
    // Generate actions for selection; populate and redraw the menus.
    // 
    createChildActions = generateCreateChildActions(newChildDescriptors, selection);
    createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection);
    if (createChildMenuManager != null) {
        populateManager(createChildMenuManager, createChildActions, null);
        createChildMenuManager.update(true);
    }
    if (createSiblingMenuManager != null) {
        populateManager(createSiblingMenuManager, createSiblingActions, null);
        createSiblingMenuManager.update(true);
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) IEditingDomainProvider(org.eclipse.emf.edit.domain.IEditingDomainProvider)

Example 10 with IEditingDomainProvider

use of org.eclipse.emf.edit.domain.IEditingDomainProvider in project InformationSystem by ObeoNetwork.

the class SoaActionBarContributor method selectionChanged.

/**
 * This implements
 * {@link org.eclipse.jface.viewers.ISelectionChangedListener}, handling
 * {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for
 * the children and siblings that can be added to the selected object and
 * updating the menus accordingly. <!-- begin-user-doc --> <!-- end-user-doc
 * -->
 *
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event) {
    // 
    if (createChildMenuManager != null) {
        depopulateManager(createChildMenuManager, createChildActions);
    }
    if (createSiblingMenuManager != null) {
        depopulateManager(createSiblingMenuManager, createSiblingActions);
    }
    // Query the new selection for appropriate new child/sibling descriptors
    // 
    Collection<?> newChildDescriptors = null;
    Collection<?> newSiblingDescriptors = null;
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
        Object object = ((IStructuredSelection) selection).getFirstElement();
        EditingDomain domain = ((IEditingDomainProvider) activeEditorPart).getEditingDomain();
        newChildDescriptors = domain.getNewChildDescriptors(object, null);
        newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
    }
    // Generate actions for selection; populate and redraw the menus.
    // 
    createChildActions = generateCreateChildActions(newChildDescriptors, selection);
    createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection);
    if (createChildMenuManager != null) {
        populateManager(createChildMenuManager, createChildActions, null);
        createChildMenuManager.update(true);
    }
    if (createSiblingMenuManager != null) {
        populateManager(createSiblingMenuManager, createSiblingActions, null);
        createSiblingMenuManager.update(true);
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) EObject(org.eclipse.emf.ecore.EObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) IEditingDomainProvider(org.eclipse.emf.edit.domain.IEditingDomainProvider)

Aggregations

IEditingDomainProvider (org.eclipse.emf.edit.domain.IEditingDomainProvider)33 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)32 ISelection (org.eclipse.jface.viewers.ISelection)30 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 IEditorPart (org.eclipse.ui.IEditorPart)2 ArrayList (java.util.ArrayList)1 URIEditorInput (org.eclipse.emf.common.ui.URIEditorInput)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorReference (org.eclipse.ui.IEditorReference)1