Search in sources :

Example 1 with ShapeStyle

use of org.eclipse.gmf.runtime.notation.ShapeStyle 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 ShapeStyle

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

the class EntryViewFactory method initializeFromPreferences.

@Override
protected void initializeFromPreferences(View view) {
    super.initializeFromPreferences(view);
    ShapeStyle style = (ShapeStyle) view.getStyle(NotationPackage.Literals.SHAPE_STYLE);
    style.setFillColor(FigureUtilities.RGBToInteger(ColorConstants.black.getRGB()));
    style.setLineColor(FigureUtilities.RGBToInteger(ColorConstants.white.getRGB()));
}
Also used : ShapeStyle(org.eclipse.gmf.runtime.notation.ShapeStyle)

Example 3 with ShapeStyle

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

the class StateViewFactory method decorateView.

@SuppressWarnings("unchecked")
@Override
protected void decorateView(View containerView, View view, IAdaptable semanticAdapter, String semanticHint, int index, boolean persisted) {
    super.decorateView(containerView, view, semanticAdapter, semanticHint, index, persisted);
    IAdaptable eObjectAdapter = null;
    EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
    if (eObject != null) {
        eObjectAdapter = new EObjectAdapter(eObject);
    }
    // State name
    FactoryUtils.createLabel(view, SemanticHints.STATE_NAME);
    // Text compartment
    getViewService().createNode(eObjectAdapter, view, SemanticHints.STATE_TEXT_COMPARTMENT, ViewUtil.APPEND, true, getPreferencesHint());
    // Figure compartment
    getViewService().createNode(eObjectAdapter, view, SemanticHints.STATE_FIGURE_COMPARTMENT, ViewUtil.APPEND, true, getPreferencesHint());
    // Create a boolean value style that indicates the alignment of
    // subregions
    BooleanValueStyle layout = (BooleanValueStyle) NotationFactory.eINSTANCE.createBooleanValueStyle();
    layout.setBooleanValue(true);
    layout.setName(ALIGNMENT_ORIENTATION);
    view.getStyles().add(layout);
    IPreferenceStore store = (IPreferenceStore) getPreferencesHint().getPreferenceStore();
    if (store == null) {
        return;
    }
    // Create states default styles
    ShapeStyle style = (ShapeStyle) view.getStyle(NotationPackage.Literals.SHAPE_STYLE);
    RGB fillRGB = PreferenceConverter.getColor(store, StatechartPreferenceConstants.PREF_STATE_BACKGROUND);
    style.setFillColor(FigureUtilities.RGBToInteger(fillRGB));
    RGB lineRGB = PreferenceConverter.getColor(store, StatechartPreferenceConstants.PREF_STATE_LINE);
    style.setLineColor(FigureUtilities.RGBToInteger(lineRGB));
}
Also used : BooleanValueStyle(org.eclipse.gmf.runtime.notation.BooleanValueStyle) IAdaptable(org.eclipse.core.runtime.IAdaptable) EObject(org.eclipse.emf.ecore.EObject) ShapeStyle(org.eclipse.gmf.runtime.notation.ShapeStyle) EObjectAdapter(org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) RGB(org.eclipse.swt.graphics.RGB)

Example 4 with ShapeStyle

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

the class StatechartTextFactory method decorateView.

@Override
protected void decorateView(View containerView, View view, IAdaptable semanticAdapter, String semanticHint, int index, boolean persisted) {
    super.decorateView(containerView, view, semanticAdapter, semanticHint, index, persisted);
    IAdaptable eObjectAdapter = null;
    EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
    if (eObject != null) {
        eObjectAdapter = new EObjectAdapter(eObject);
    }
    // Create the statechart name label
    FactoryUtils.createLabel(view, STATECHART_NAME);
    // create the expressions compartment
    Node textCompartment = getViewService().createNode(eObjectAdapter, view, STATECHART_TEXT_EXPRESSION, ViewUtil.APPEND, true, getPreferencesHint());
    Assert.isNotNull(textCompartment);
    ShapeStyle style = (ShapeStyle) view.getStyle(NotationPackage.eINSTANCE.getShapeStyle());
    style.setFillColor(FigureUtilities.RGBToInteger(ColorConstants.white.getRGB()));
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) EObject(org.eclipse.emf.ecore.EObject) Node(org.eclipse.gmf.runtime.notation.Node) ShapeStyle(org.eclipse.gmf.runtime.notation.ShapeStyle) EObjectAdapter(org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter)

Example 5 with ShapeStyle

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

the class FactoryUtils method createLabel.

/**
 * Creates a Label view
 *
 * @param owner
 * @param hint
 * @return
 */
@SuppressWarnings("unchecked")
public static Node createLabel(View owner, String hint) {
    DecorationNode nameLabel = NotationFactory.eINSTANCE.createDecorationNode();
    nameLabel.setType(hint);
    ShapeStyle style = NotationFactory.eINSTANCE.createShapeStyle();
    style.setFontColor(FigureUtilities.RGBToInteger(ColorConstants.black.getRGB()));
    nameLabel.getStyles().add(style);
    ViewUtil.insertChildView(owner, nameLabel, ViewUtil.APPEND, true);
    nameLabel.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
    return nameLabel;
}
Also used : ShapeStyle(org.eclipse.gmf.runtime.notation.ShapeStyle) DecorationNode(org.eclipse.gmf.runtime.notation.DecorationNode)

Aggregations

ShapeStyle (org.eclipse.gmf.runtime.notation.ShapeStyle)6 IAdaptable (org.eclipse.core.runtime.IAdaptable)3 EObject (org.eclipse.emf.ecore.EObject)3 RGB (org.eclipse.swt.graphics.RGB)3 EObjectAdapter (org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter)2 Node (org.eclipse.gmf.runtime.notation.Node)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)1 BooleanValueStyle (org.eclipse.gmf.runtime.notation.BooleanValueStyle)1 ConnectorStyle (org.eclipse.gmf.runtime.notation.ConnectorStyle)1 DecorationNode (org.eclipse.gmf.runtime.notation.DecorationNode)1 Edge (org.eclipse.gmf.runtime.notation.Edge)1 View (org.eclipse.gmf.runtime.notation.View)1 Color (org.eclipse.swt.graphics.Color)1