org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart Java Examples

The following examples show how to use org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart. 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: CopyToImageUtilEx.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public byte [] copyToImageByteArray(final Diagram diagram,final Element elementToDraw, final int maxWidth, final int maxHeight, final ImageFileFormat format, final IProgressMonitor monitor, final PreferencesHint preferencesHint, final boolean useMargins) throws Exception {
	final Shell shell = new Shell();
	DiagramEditPart diagramEditPart = null ;
	EditPart ep = null ;
	try {
		diagramEditPart = createDiagramEditPart(diagram,
				shell, preferencesHint);
		Assert.isNotNull(diagramEditPart);
		ep = GMFTools.findEditPart(diagramEditPart,elementToDraw) ;


		if(ep == null) {
               throw new Exception("Element to draw not found") ;
           }

		return copyToImageByteArray(diagramEditPart, Collections.singletonList(ep), maxWidth, maxHeight, format, monitor, useMargins);
	}catch(final Exception e){
		e.printStackTrace();
		throw e ;
	} finally {
		shell.dispose();
	}
}
 
Example #2
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 #3
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 #4
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 #5
Source File: ImporterUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static  void updateActiviesSize(DiagramEditPart root) {
    resizeActivities(root);
    for(Object o : root.getChildren()){
        if(o instanceof PoolEditPart){
            for(Object child :((PoolEditPart) o).getChildren()){
                if(child instanceof PoolPoolCompartmentEditPart){
                    resizeActivities((EditPart) child);
                    for(Object laneChild : ((PoolPoolCompartmentEditPart) child).getChildren()){
                        if(laneChild instanceof LaneEditPart){
                            for(Object child2 : ((LaneEditPart) laneChild).getChildren()){
                                if(child2 instanceof LaneLaneCompartmentEditPart){
                                    resizeActivities((EditPart) child2);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example #6
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 #7
Source File: MessageFlowFactory.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void removeMessageFlow(TransactionalEditingDomain editingDomain, AbstractCatchMessageEvent target,
        DiagramEditPart dep) {

    EditPart ep = findEditPart(dep, target);
    CompositeCommand command = new CompositeCommand("Remove MessageFlows");

    for (Object connection : ((AbstractGraphicalEditPart) ep).getTargetConnections()) {
        if (connection instanceof MessageFlowEditPart) {
            MessageFlowEditPart connectionPart = (MessageFlowEditPart) connection;
            MessageFlow flow = (MessageFlow) connectionPart.resolveSemanticElement();
            SetCommand c = new SetCommand(editingDomain, flow.getTarget(),
                    ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT, null);
            editingDomain.getCommandStack().execute(c);
            command.add(new DeleteCommand(editingDomain, connectionPart.getPrimaryView()));
            DestroyElementRequest req = new DestroyElementRequest(editingDomain, flow, false);
            DestroyElementCommand rmComd = new DestroyElementCommand(req);
            command.add(rmComd);
        }
    }

    dep.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(command.reduce()));
    dep.getDiagramEditDomain().getDiagramCommandStack().flush();
    dep.refresh();
}
 
Example #8
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
private static void validate(DiagramEditPart diagramEditPart, View view) {
	IFile target = view.eResource() != null ? WorkspaceSynchronizer.getFile(view.eResource()) : null;
	if (target != null) {
		ProcessMarkerNavigationProvider.deleteMarkers(target);
	}
	Diagnostic diagnostic = runEMFValidator(view);
	createMarkers(target, diagnostic, diagramEditPart);
	IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance()
			.newValidator(EvaluationMode.BATCH);
	validator.setIncludeLiveConstraints(true);
	if (view.isSetElement() && view.getElement() != null) {
		IStatus status = validator.validate(view.getElement());
		createMarkers(target, status, diagramEditPart);
	}
}
 
Example #9
Source File: DefaultPapyrusModelManager.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void addElementsToDiagram(Diagram diagram, IProgressMonitor monitor) {
	Element container = diagramManager.getDiagramContainer(diagram);
	AbstractDiagramElementsManager diagramElementsManager;
	DiagramEditPart diagep = diagramManager.getActiveDiagramEditPart();
	if(diagram.getType().equals("PapyrusUMLClassDiagram")){					
		diagramElementsManager = new ClassDiagramElementsManager(diagep);
	}else if(diagram.getType().equals("PapyrusUMLActivityDiagram")){
		diagramElementsManager = new ActivityDiagramElementsManager(diagep);
	}else if(diagram.getType().equals("PapyrusUMLStateMachineDiagram")){
		diagramElementsManager = new StateMachineDiagramElementsManager(diagep);
	}else{
		return;
	}
	
	List<Element> baseElements = modelManager.getAllChildrenOfPackage(container);
	diagramElementsManager.addElementsToDiagram(baseElements);
}
 
Example #10
Source File: MessageFlowFactory.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static void editMessageFlowName(Message message, AbstractCatchMessageEvent target, DiagramEditPart dep) {
    EditPart targetEP = findEditPart(dep, target);
    Optional<MessageFlowEditPart> connectionPart = ((AbstractGraphicalEditPart) targetEP).getTargetConnections().stream()
            .filter(MessageFlowEditPart.class::isInstance)
            .map(MessageFlowEditPart.class::cast)
            .findFirst();
    if (connectionPart.isPresent()) {
        MessageFlow messageFlowToEdit = (MessageFlow) connectionPart.get().resolveSemanticElement();
        EMFModelUpdater<MessageFlow> updater = new EMFModelUpdater<>();
        MessageFlow workingCopy = updater.from(messageFlowToEdit).getWorkingCopy();
        workingCopy.setName(message.getName());
        updater.update();
        dep.refresh();
    }
}
 
Example #11
Source File: TextAnnotation2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #12
Source File: BatchValidationOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected DiagramEditPart createDiagramEditPart(final Diagram d) {
    if (d != null && d.eResource() != null) {
        DiagramEditPart offscreenDiagramEditPart = null;
        try {
            offscreenDiagramEditPart = offscreenEditPartFactory.createOffscreenDiagramEditPart(d);
        } catch (final Exception e) {
            //Need to call twice because sometimes for unknown reasons, the first time is not working
            offscreenDiagramEditPart = offscreenEditPartFactory.createOffscreenDiagramEditPart(d);
        }
        return offscreenDiagramEditPart;
    }
    return null;
}
 
Example #13
Source File: StartMessageEvent2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #14
Source File: StartMessageEventEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #15
Source File: EndErrorEvent2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #16
Source File: ColorAndFontPropertySection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private DiagramEditPart getCurrentDiagramEditPart() {
	IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() ;
	if(editor instanceof DiagramEditor){
		return ((DiagramEditor)editor).getDiagramEditPart();
	}
	return null;
}
 
Example #17
Source File: IntermediateErrorCatchEvent5EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public java.lang.Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #18
Source File: BoundaryTimerEventEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public java.lang.Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #19
Source File: IntermediateThrowSignalEvent2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #20
Source File: CustomSubprocessEventCompartmentEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object getAdapter(Class key) {

    if (key == SnapToHelper.class) {
        EditPart parent = getParent();
        while (!(parent instanceof DiagramEditPart)) {
            parent = parent.getParent();
        }
        return GMFTools.getSnapHelper((GraphicalEditPart) parent);
    }

    return super.getAdapter(key);
}
 
Example #21
Source File: BatchValidationOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected DiagramEditPart retrieveEditPartFromOpenedEditors(final Diagram d) {
    final IWorkbenchPage activePage = getActivePage();
    if (activePage != null) {
        for (final IEditorReference ep : activePage.getEditorReferences()) {
            final IEditorPart editor = ep.getEditor(false);
            if (editor instanceof DiagramEditor
                    && ((DiagramEditor) editor).getDiagram().equals(d)
                    && ((DiagramEditor) editor).getDiagramEditPart() != null) {
                    return ((DiagramEditor) editor).getDiagramEditPart();
                }
        }
    }
    return null;
}
 
Example #22
Source File: CallActivityEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #23
Source File: BatchValidationOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void validate(final DiagramEditPart diagramEditPart, final View view, final IProgressMonitor monitor) {
    final IFile target = view.eResource() != null ? WorkspaceSynchronizer.getFile(view.eResource()) : null;
    final Diagnostic diagnostic = validationMarkerProvider.runEMFValidator(view);
    validationMarkerProvider.createMarkers(target, diagnostic, diagramEditPart);
    final IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance().newValidator(
            EvaluationMode.BATCH);
    validator.setIncludeLiveConstraints(true);
    if (view.isSetElement() && view.getElement() != null && view.getElement().eResource() != null) {
        final IStatus status = validator.validate(view.getElement(), monitor);
        validationMarkerProvider.createMarkers(target, status, diagramEditPart);
    }
}
 
Example #24
Source File: ANDGateway2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #25
Source File: EndTerminatedEvent2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #26
Source File: SubProcessEvent2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #27
Source File: EndTerminatedEventEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #28
Source File: IntermediateThrowMessageEventEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @Generated BonitaSoft
 */
@Override
public Object getAdapter(Class key) {

	if (key == SnapToHelper.class) {
		EditPart parent = getParent();
		while (!(parent instanceof DiagramEditPart)) {
			parent = parent.getParent();
		}
		return GMFTools.getSnapHelper((GraphicalEditPart) parent);
	}

	return super.getAdapter(key);
}
 
Example #29
Source File: OffscreenEditPartFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public DiagramEditPart createOffscreenDiagramEditPart(final Diagram d) {
    final EObject element = d.getElement();
    if (element != null) {
        final OffscreenDiagramEditPartRunnable runnable = new OffscreenDiagramEditPartRunnable(d, factory);
        if (inUIThread()) {
            runnable.run();
        } else {
            runInUI(runnable);
        }

        toDispose.add(runnable.getDisposable());
        return runnable.getDiagramEditPart();
    }
    return null;
}
 
Example #30
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;
}