From 7f5906498b939c3023470fca214910cfe1373110 Mon Sep 17 00:00:00 2001 From: Quentin Le Menez Date: Wed, 20 Dec 2017 10:03:59 +0100 Subject: Bug 528992 - [CSS] There should be a way to remove a style - Add a new remove style command Change-Id: I10086c959aee83239bd5198499a060663b6ae269 Signed-off-by: Quentin Le Menez (cherry picked from commit 4da7dfa2a6d3d35a1e4f52289b669c710d300ebd) --- .../databinding/RemoveCssClassStyleCommand.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveCssClassStyleCommand.java (limited to 'plugins/infra') diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveCssClassStyleCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveCssClassStyleCommand.java new file mode 100755 index 00000000000..11ea8743fb9 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveCssClassStyleCommand.java @@ -0,0 +1,74 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST and others. + * + * 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: + * 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; + +/** + * @author Quentin Le Menez + * + */ +public class RemoveCssClassStyleCommand extends RecordingCommand implements Command { + + private Collection views; + + private String style; + + /** + * Constructor. + * + * @param namedStyle + * @param newValue + */ + public RemoveCssClassStyleCommand(TransactionalEditingDomain domain, View view, String newValue) { + this(domain, Collections.singleton(view), newValue); + } + + public RemoveCssClassStyleCommand(TransactionalEditingDomain domain, Collection views, String style) { + super(domain); + this.views = views; + this.style = style; + } + + + /** + * Remove the style to the existing list or do nothing if there are no styles applied + * + * @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) { + // there is no style applied to this view + return; + } + if (style != null && namedStyle.getStringListValue().contains(style)) { + namedStyle.getStringListValue().remove(style); + } + } + } + +} -- cgit v1.2.3