Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2017-11-14 14:33:24 +0000
committerBenoit Maggi2017-11-20 11:33:22 +0000
commit5afa41f30f3f7a556cb3fdbee14a90733af607a6 (patch)
tree9bdb236ef76808d8044c5ba7cf9931ce48c73587
parent18b714785f83b6b86d8101397e5a092fefae09dd (diff)
downloadorg.eclipse.papyrus-5afa41f30f3f7a556cb3fdbee14a90733af607a6.tar.gz
org.eclipse.papyrus-5afa41f30f3f7a556cb3fdbee14a90733af607a6.tar.xz
org.eclipse.papyrus-5afa41f30f3f7a556cb3fdbee14a90733af607a6.zip
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 <benoit.maggi@cea.fr>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/plugin.xml18
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/ApplyStyleHandler.java87
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddCssClassStyleCommand.java72
3 files changed, 177 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/plugin.xml b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/plugin.xml
index 4c4cd0021d4..292c0bbd300 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/plugin.xml
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/plugin.xml
@@ -26,6 +26,14 @@
checkEnabled="true">
</visibleWhen>
</command>
+ <command
+ commandId="org.eclipse.papyrus.infra.gmfdiag.css.applyStyle"
+ icon="icons/sourceEditor.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
</menuContribution>
</extension>
<extension
@@ -41,10 +49,20 @@
id="org.eclipse.papyrus.infra.gmfdiag.css.editStyle"
name="Edit an existing style">
</command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="Apply a style on the selected item"
+ id="org.eclipse.papyrus.infra.gmfdiag.css.applyStyle"
+ name="Apply a style">
+ </command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
+ class="org.eclipse.papyrus.infra.gmfdiag.css.configuration.handler.ApplyStyleHandler"
+ commandId="org.eclipse.papyrus.infra.gmfdiag.css.applyStyle">
+ </handler>
+ <handler
class="org.eclipse.papyrus.infra.gmfdiag.css.configuration.handler.CreateStyleHandler"
commandId="org.eclipse.papyrus.infra.gmfdiag.css.createStyle">
</handler>
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/ApplyStyleHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/ApplyStyleHandler.java
new file mode 100644
index 00000000000..d4961793a6f
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/ApplyStyleHandler.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * 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.configuration.handler;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.configuration.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding.AddCssClassStyleCommand;
+import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
+import org.eclipse.papyrus.infra.widgets.editors.InputDialog;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Apply a style to a view using a right click menu
+ */
+public class ApplyStyleHandler extends AbstractHandler {
+
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection;
+ try {
+ selection = ServiceUtilsForHandlers.getInstance().getNestedActiveIEditorPart(event).getSite().getSelectionProvider().getSelection();
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Iterator iterator = ((IStructuredSelection) selection).iterator();
+ List<View> selectedViews = new ArrayList<>();
+ while (iterator.hasNext()) {
+ Object it = iterator.next();
+ View view = NotationHelper.findView(it);
+ if (view != null) {
+ selectedViews.add(view);
+ }
+ }
+
+ if (!selectedViews.isEmpty()) {
+ Shell parentShell = ((Event) event.getTrigger()).widget.getDisplay().getActiveShell();
+ InputDialog dialog = new InputDialog(parentShell, Messages.StringEditionFactory_EnterANewValue, Messages.StringEditionFactory_EnterANewValue, "", null); //$NON-NLS-1$
+ int result = dialog.open();
+ if (result == Window.OK) {
+ String newStyleValue = dialog.getText();
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(selectedViews.get(0));
+ AddCssClassStyleCommand addCssClassStyleCommand = new AddCssClassStyleCommand(editingDomain, selectedViews, newStyleValue);
+ editingDomain.getCommandStack().execute(addCssClassStyleCommand);
+ return newStyleValue;
+ }
+ }
+
+ }
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+ return null;
+ }
+
+
+}
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<View> 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<View> 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);
+ }
+
+
+ }
+
+}

Back to the top