Search in sources :

Example 1 with ConnectorStyle

use of org.eclipse.gmf.runtime.notation.ConnectorStyle in project statecharts by Yakindu.

the class SimulationImageRenderer method highlightElements.

public void highlightElements(final List<? extends EObject> objects, final Diagram diagram) {
    AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(TransactionUtil.getEditingDomain(diagram), "", null) {

        @Override
        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            // Init colors from preferences
            RGB rgbForeGround = PreferenceConverter.getColor(SimulationActivator.getDefault().getPreferenceStore(), SimulationPreferenceConstants.STATE_FOREGROUND_HIGHLIGHTING_COLOR);
            RGB rgbBackGround = PreferenceConverter.getColor(SimulationActivator.getDefault().getPreferenceStore(), SimulationPreferenceConstants.STATE_BACKGROUND_HIGHLIGHTING_COLOR);
            RGB rgbTransitionActive = PreferenceConverter.getColor(SimulationActivator.getDefault().getPreferenceStore(), SimulationPreferenceConstants.TRANSITION_HIGHLIGHTING_COLOR);
            Color color = new Color(Display.getDefault(), rgbForeGround);
            Integer foreGround = FigureUtilities.colorToInteger(color);
            color.dispose();
            color = new Color(Display.getDefault(), rgbBackGround);
            Integer background = FigureUtilities.colorToInteger(color);
            color.dispose();
            color = new Color(Display.getDefault(), rgbTransitionActive);
            Integer transitionActive = FigureUtilities.colorToInteger(color);
            color.dispose();
            // Set styling
            TreeIterator<EObject> eAllContents = diagram.eAllContents();
            while (eAllContents.hasNext()) {
                EObject next = eAllContents.next();
                if (next instanceof View) {
                    for (EObject elementToHighlight : objects) {
                        EObject element = null;
                        if (next instanceof Node) {
                            element = ((Node) next).getElement();
                        } else if (next instanceof Edge) {
                            element = ((Edge) next).getElement();
                        }
                        if (element == null) {
                            // next instanceof BasicDecorationNode || next instanceof Shape
                            continue;
                        }
                        if (EcoreUtil.getURI(elementToHighlight).equals(EcoreUtil.getURI(element))) {
                            if (next instanceof Node) {
                                ShapeStyle style = (ShapeStyle) ((Node) next).getStyle(NotationPackage.Literals.SHAPE_STYLE);
                                if (style != null) {
                                    style.setFillColor(background);
                                    style.setLineColor(foreGround);
                                }
                            } else if (next instanceof Edge) {
                                ConnectorStyle style = (ConnectorStyle) ((View) next).getStyle(NotationPackage.Literals.CONNECTOR_STYLE);
                                if (style != null) {
                                    style.setLineColor(transitionActive);
                                }
                            }
                        }
                    }
                }
            }
            return CommandResult.newOKCommandResult();
        }
    };
    try {
        cmd.execute(new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Color(org.eclipse.swt.graphics.Color) Node(org.eclipse.gmf.runtime.notation.Node) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) RGB(org.eclipse.swt.graphics.RGB) View(org.eclipse.gmf.runtime.notation.View) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConnectorStyle(org.eclipse.gmf.runtime.notation.ConnectorStyle) EObject(org.eclipse.emf.ecore.EObject) ShapeStyle(org.eclipse.gmf.runtime.notation.ShapeStyle) ExecutionException(org.eclipse.core.commands.ExecutionException) Edge(org.eclipse.gmf.runtime.notation.Edge)

Example 2 with ConnectorStyle

use of org.eclipse.gmf.runtime.notation.ConnectorStyle in project statecharts by Yakindu.

the class SetLabelsOffsetOperation method isEdgeWithObliqueRoutingStyle.

public static boolean isEdgeWithObliqueRoutingStyle(org.eclipse.gef.ConnectionEditPart part) {
    Edge edge = (Edge) part.getModel();
    ConnectorStyle style = (ConnectorStyle) edge.getStyle(NotationPackage.Literals.CONNECTOR_STYLE);
    if (style != null) {
        return Routing.MANUAL_LITERAL == style.getRouting();
    }
    return false;
}
Also used : ConnectorStyle(org.eclipse.gmf.runtime.notation.ConnectorStyle) Edge(org.eclipse.gmf.runtime.notation.Edge)

Aggregations

ConnectorStyle (org.eclipse.gmf.runtime.notation.ConnectorStyle)2 Edge (org.eclipse.gmf.runtime.notation.Edge)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 EObject (org.eclipse.emf.ecore.EObject)1 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)1 Node (org.eclipse.gmf.runtime.notation.Node)1 ShapeStyle (org.eclipse.gmf.runtime.notation.ShapeStyle)1 View (org.eclipse.gmf.runtime.notation.View)1 Color (org.eclipse.swt.graphics.Color)1 RGB (org.eclipse.swt.graphics.RGB)1