From 5afa41f30f3f7a556cb3fdbee14a90733af607a6 Mon Sep 17 00:00:00 2001 From: Benoit Maggi Date: Tue, 14 Nov 2017 15:33:24 +0100 Subject: Bug 518305 - Apply a predefined Style directly from a diagram - add apply style menu on right click - also works with multi-selection Change-Id: I445331e15aaf9a1bbdb1f2d229297b75bce8197f Signed-off-by: Benoit Maggi --- .../databinding/AddCssClassStyleCommand.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddCssClassStyleCommand.java (limited to 'plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties') diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddCssClassStyleCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddCssClassStyleCommand.java new file mode 100644 index 00000000000..1041bab9e02 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddCssClassStyleCommand.java @@ -0,0 +1,72 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Benoit Maggi (CEA LIST) - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.StringListValueStyle; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSStyles; + + +/** + * EMF Command to add a new style + * Stored in Notation with CSSStyles.CSS_GMF_CLASS_KEY + */ +public class AddCssClassStyleCommand extends RecordingCommand implements Command { + + private Collection views; + + private String style; + + /** + * Constructor. + * + * @param namedStyle + * @param newValue + */ + public AddCssClassStyleCommand(TransactionalEditingDomain domain, View view, String newValue) { + this(domain, Collections.singleton(view), newValue); + } + + public AddCssClassStyleCommand(TransactionalEditingDomain domain, Collection views, String style) { + super(domain); + this.views = views; + this.style = style; + } + + + /** + * Add the style to the existing list or initialize a new list with it + * @see org.eclipse.emf.transaction.RecordingCommand#doExecute() + * + */ + @Override + protected void doExecute() { + for (View view : views) { + StringListValueStyle namedStyle = (StringListValueStyle) view.getNamedStyle(NotationPackage.eINSTANCE.getStringListValueStyle(), CSSStyles.CSS_GMF_CLASS_KEY); + if (namedStyle == null) { + namedStyle = (StringListValueStyle) view.createStyle(NotationPackage.eINSTANCE.getStringListValueStyle()); + namedStyle.setName(CSSStyles.CSS_GMF_CLASS_KEY); + } + namedStyle.getStringListValue().add(style); + } + + + } + +} -- cgit v1.2.3