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 /plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src
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>
Diffstat (limited to 'plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src')
-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
1 files changed, 87 insertions, 0 deletions
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;
+ }
+
+
+}

Back to the top