org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil Java Examples

The following examples show how to use org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValidateAction.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
private static void createMarkers(IFile target, IStatus validationStatus, DiagramEditPart diagramEditPart) {
	if (validationStatus.isOK()) {
		return;
	}
	final IStatus rootStatus = validationStatus;
	List allStatuses = new ArrayList();
	CrossflowDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new CrossflowDiagramEditorUtil.LazyElement2ViewMap(
			diagramEditPart.getDiagramView(),
			collectTargetElements(rootStatus, new HashSet<EObject>(), allStatuses));
	for (Iterator it = allStatuses.iterator(); it.hasNext();) {
		IConstraintStatus nextStatus = (IConstraintStatus) it.next();
		View view = CrossflowDiagramEditorUtil.findView(diagramEditPart, nextStatus.getTarget(), element2ViewMap);
		addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
				EMFCoreUtil.getQualifiedName(nextStatus.getTarget(), true), nextStatus.getMessage(),
				nextStatus.getSeverity());
	}
}
 
Example #2
Source File: ValidateAction.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
private static void createMarkers(IFile target, Diagnostic emfValidationStatus, DiagramEditPart diagramEditPart) {
	if (emfValidationStatus.getSeverity() == Diagnostic.OK) {
		return;
	}
	final Diagnostic rootStatus = emfValidationStatus;
	List allDiagnostics = new ArrayList();
	CrossflowDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new CrossflowDiagramEditorUtil.LazyElement2ViewMap(
			diagramEditPart.getDiagramView(),
			collectTargetElements(rootStatus, new HashSet<EObject>(), allDiagnostics));
	for (Iterator it = emfValidationStatus.getChildren().iterator(); it.hasNext();) {
		Diagnostic nextDiagnostic = (Diagnostic) it.next();
		List data = nextDiagnostic.getData();
		if (data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
			EObject element = (EObject) data.get(0);
			View view = CrossflowDiagramEditorUtil.findView(diagramEditPart, element, element2ViewMap);
			addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
					EMFCoreUtil.getQualifiedName(element, true), nextDiagnostic.getMessage(),
					diagnosticToStatusSeverity(nextDiagnostic.getSeverity()));
		}
	}
}
 
Example #3
Source File: ValidationMarkerProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void createMarkers(final IFile
        target, final Diagnostic emfValidationStatus, final DiagramEditPart diagramEditPart) {
    if (emfValidationStatus.getSeverity() == Diagnostic.OK) {
        return;
    }
    final Diagnostic rootStatus = emfValidationStatus;
    final List allDiagnostics = new ArrayList();
    final ProcessDiagramEditorUtil.LazyElement2ViewMap element2ViewMap =
            new ProcessDiagramEditorUtil.LazyElement2ViewMap(
                    diagramEditPart.getDiagramView(),
                    collectTargetElements(rootStatus, new HashSet<EObject>(), allDiagnostics));
    for (final Iterator it = emfValidationStatus.getChildren().iterator(); it.hasNext();) {
        final Diagnostic nextDiagnostic = (Diagnostic) it.next();
        final List data = nextDiagnostic.getData();
        if (data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
            final EObject element = (EObject) data.get(0);
            final View view = ProcessDiagramEditorUtil.findView(
                    diagramEditPart, element, element2ViewMap);
            addMarker(diagramEditPart, null, diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
                    EMFCoreUtil.getQualifiedName(element, true),
                    nextDiagnostic.getMessage(), diagnosticToStatusSeverity(nextDiagnostic.getSeverity()));
        }
    }
}
 
Example #4
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
private static void createMarkers(IFile target, IStatus validationStatus, DiagramEditPart diagramEditPart) {
	if (validationStatus.isOK()) {
		return;
	}
	final IStatus rootStatus = validationStatus;
	List allStatuses = new ArrayList();
	ProcessDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new ProcessDiagramEditorUtil.LazyElement2ViewMap(
			diagramEditPart.getDiagramView(),
			collectTargetElements(rootStatus, new HashSet<EObject>(), allStatuses));
	for (Iterator it = allStatuses.iterator(); it.hasNext();) {
		IConstraintStatus nextStatus = (IConstraintStatus) it.next();
		View view = ProcessDiagramEditorUtil.findView(diagramEditPart, nextStatus.getTarget(), element2ViewMap);
		addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
				EMFCoreUtil.getQualifiedName(nextStatus.getTarget(), true), nextStatus.getMessage(),
				nextStatus.getSeverity());
	}
}
 
Example #5
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
private static void createMarkers(IFile target, Diagnostic emfValidationStatus, DiagramEditPart diagramEditPart) {
	if (emfValidationStatus.getSeverity() == Diagnostic.OK) {
		return;
	}
	final Diagnostic rootStatus = emfValidationStatus;
	List allDiagnostics = new ArrayList();
	ProcessDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new ProcessDiagramEditorUtil.LazyElement2ViewMap(
			diagramEditPart.getDiagramView(),
			collectTargetElements(rootStatus, new HashSet<EObject>(), allDiagnostics));
	for (Iterator it = emfValidationStatus.getChildren().iterator(); it.hasNext();) {
		Diagnostic nextDiagnostic = (Diagnostic) it.next();
		List data = nextDiagnostic.getData();
		if (data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
			EObject element = (EObject) data.get(0);
			View view = ProcessDiagramEditorUtil.findView(diagramEditPart, element, element2ViewMap);
			addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
					EMFCoreUtil.getQualifiedName(element, true), nextDiagnostic.getMessage(),
					diagnosticToStatusSeverity(nextDiagnostic.getSeverity()));
		}
	}
}
 
Example #6
Source File: CrossflowDiagramEditorUtil.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private static int findElementsInDiagramByID(DiagramEditPart diagramPart, EObject element,
		List<EditPart> editPartCollector) {
	IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer) diagramPart.getViewer();
	final int intialNumOfEditParts = editPartCollector.size();

	if (element instanceof View) { // support notation element lookup
		EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(element);
		if (editPart != null) {
			editPartCollector.add(editPart);
			return 1;
		}
	}

	String elementID = EMFCoreUtil.getProxyID(element);
	@SuppressWarnings("unchecked")
	List<EditPart> associatedParts = viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class);
	// perform the possible hierarchy disjoint -> take the top-most parts only
	for (EditPart nextPart : associatedParts) {
		EditPart parentPart = nextPart.getParent();
		while (parentPart != null && !associatedParts.contains(parentPart)) {
			parentPart = parentPart.getParent();
		}
		if (parentPart == null) {
			editPartCollector.add(nextPart);
		}
	}

	if (intialNumOfEditParts == editPartCollector.size()) {
		if (!associatedParts.isEmpty()) {
			editPartCollector.add(associatedParts.get(0));
		} else {
			if (element.eContainer() != null) {
				return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
			}
		}
	}
	return editPartCollector.size() - intialNumOfEditParts;
}
 
Example #7
Source File: ValidateAction.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private static Diagnostic runEMFValidator(View target) {
	if (target.isSetElement() && target.getElement() != null) {
		return new Diagnostician() {

			public String getObjectLabel(EObject eObject) {
				return EMFCoreUtil.getQualifiedName(eObject, true);
			}
		}.validate(target.getElement());
	}
	return Diagnostic.OK_INSTANCE;
}
 
Example #8
Source File: CrossflowViewProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private EObject getSemanticElement(IAdaptable semanticAdapter) {
	if (semanticAdapter == null) {
		return null;
	}
	EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
	if (eObject != null) {
		return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
	}
	return null;
}
 
Example #9
Source File: SharedEditingDomainFactory.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void collectTransitiveReferences(Resource resource, Set<Resource> references) {
	EList<Resource> resources = resource.getResourceSet().getResources();
	for (Resource currentResource : resources) {
		final Collection<Resource> allImports = EMFCoreUtil.getImports(currentResource);
		for (Resource currentImport : allImports) {
			if (currentImport == resource) {
				if (!references.contains(currentResource)) {
					references.add(currentResource);
					collectTransitiveReferences(currentResource, references);
				}
			}
		}
	}
}
 
Example #10
Source File: ValidationMarkerProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public Diagnostic runEMFValidator(final View target) {
    if (target.isSetElement() && target.getElement() != null) {
        return new Diagnostician() {

            @Override
            public String getObjectLabel(final EObject eObject) {
                return EMFCoreUtil.getQualifiedName(eObject, true);
            }
        }.validate(target.getElement());
    }
    return Diagnostic.OK_INSTANCE;
}
 
Example #11
Source File: ValidationMarkerProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public void createMarkers(final IFile
        target, final IStatus validationStatus, final DiagramEditPart diagramEditPart) {
    if (validationStatus.isOK()) {
        return;
    }
    final IStatus rootStatus = validationStatus;
    final List allStatuses = new ArrayList();
    final ProcessDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new ProcessDiagramEditorUtil.LazyElement2ViewMap(
            diagramEditPart.getDiagramView(),
            collectTargetElements(rootStatus, new HashSet<EObject>(), allStatuses));
    final List<Triple<String, String, String>> createdMarkers = new ArrayList<Triple<String, String, String>>();
    for (final Iterator it = allStatuses.iterator(); it.hasNext();) {
        final IConstraintStatus nextStatus =
                (IConstraintStatus) it.next();
        final String constraintId = nextStatus.getConstraint().getDescriptor().getId();
        final View view = ProcessDiagramEditorUtil.findView(
                diagramEditPart, nextStatus.getTarget(), element2ViewMap);
        final Triple<String, String, String> triple = new Triple<String, String, String>(constraintId, nextStatus.getMessage(), view.eResource()
                .getURIFragment(view));
        if (!createdMarkers.contains(triple)) {
            addMarker(diagramEditPart, constraintId, diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
                    EMFCoreUtil.getQualifiedName(nextStatus.getTarget(), true),
                    nextStatus.getMessage(), nextStatus.getSeverity());
            createdMarkers.add(triple);
        }
    }
}
 
Example #12
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private static Diagnostic runEMFValidator(View target) {
	if (target.isSetElement() && target.getElement() != null) {
		return new Diagnostician() {

			public String getObjectLabel(EObject eObject) {
				return EMFCoreUtil.getQualifiedName(eObject, true);
			}
		}.validate(target.getElement());
	}
	return Diagnostic.OK_INSTANCE;
}
 
Example #13
Source File: ProcessDiagramEditorUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private static int findElementsInDiagramByID(DiagramEditPart diagramPart, EObject element,
		List<EditPart> editPartCollector) {
	IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer) diagramPart.getViewer();
	final int intialNumOfEditParts = editPartCollector.size();

	if (element instanceof View) { // support notation element lookup
		EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(element);
		if (editPart != null) {
			editPartCollector.add(editPart);
			return 1;
		}
	}

	String elementID = EMFCoreUtil.getProxyID(element);
	@SuppressWarnings("unchecked")
	List<EditPart> associatedParts = viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class);
	// perform the possible hierarchy disjoint -> take the top-most parts only
	for (EditPart nextPart : associatedParts) {
		EditPart parentPart = nextPart.getParent();
		while (parentPart != null && !associatedParts.contains(parentPart)) {
			parentPart = parentPart.getParent();
		}
		if (parentPart == null) {
			editPartCollector.add(nextPart);
		}
	}

	if (intialNumOfEditParts == editPartCollector.size()) {
		if (!associatedParts.isEmpty()) {
			editPartCollector.add(associatedParts.get(0));
		} else {
			if (element.eContainer() != null) {
				return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
			}
		}
	}
	return editPartCollector.size() - intialNumOfEditParts;
}
 
Example #14
Source File: ProcessViewProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private EObject getSemanticElement(IAdaptable semanticAdapter) {
	if (semanticAdapter == null) {
		return null;
	}
	EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
	if (eObject != null) {
		return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
	}
	return null;
}
 
Example #15
Source File: EditingDomainResourcesDisposer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * called to dispose the resource set when closing the editor in parameter.
 * The resource set will be unloaded only if it's not in use
 * @param resourceSet
 * @param editorInput
 */
public static void disposeEditorInput(final ResourceSet resourceSet, final IEditorInput editorInput) {
    final EList<Resource> allResources = resourceSet.getResources();
    final List<Resource> resourcesToDispose = new ArrayList<Resource>(allResources);
    IEditorReference[] editorReferences;
    if(PlatformUI.isWorkbenchRunning()){
        final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if(activePage != null){
            editorReferences = activePage.getEditorReferences();
        } else {
            return;
        }
    }else{
        return;
    }
    for (final IEditorReference editorRef : editorReferences) {
        try {
            final IEditorInput currentEditorInput = editorRef.getEditorInput();
            if (currentEditorInput != editorInput) {
                final IEditorPart openEditor = editorRef.getEditor(false);
                if (openEditor instanceof DiagramEditor) {
                    final DiagramEditor openDiagramEditor = (DiagramEditor) openEditor;
                    final ResourceSet diagramResourceSet = openDiagramEditor.getEditingDomain().getResourceSet();
                    if (diagramResourceSet == resourceSet) {
                        final Resource diagramResource = EditorUtil.getDiagramResource(diagramResourceSet, currentEditorInput);
                        if(diagramResource != null){
                            resourcesToDispose.remove(diagramResource);
                            final Collection<?> imports = EMFCoreUtil.getImports(diagramResource);
                            resourcesToDispose.removeAll(imports);
                        }
                    }
                }
            }
        } catch (final Exception e) {
            BonitaStudioLog.error(e);
        }
    }
    for (final Resource resource : resourcesToDispose) {
        try {
            resource.unload();
            allResources.remove(resource);
        } catch (final Exception t) {
            BonitaStudioLog.error(t);
        }
    }
}