Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-03-04 17:18:00 +0000
committerChristian W. Damus2015-03-05 14:17:32 +0000
commit9e9310f0b5b6ace414e75ab6800f5d4ec809ce2c (patch)
tree7c80ff50fe38e60ce034a66cacfed178575e7975 /plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties
parentcef4dddad02cc51e58facc5d59835f1befd81ab4 (diff)
downloadorg.eclipse.papyrus-9e9310f0b5b6ace414e75ab6800f5d4ec809ce2c.tar.gz
org.eclipse.papyrus-9e9310f0b5b6ace414e75ab6800f5d4ec809ce2c.tar.xz
org.eclipse.papyrus-9e9310f0b5b6ace414e75ab6800f5d4ec809ce2c.zip
Bug 461432: [CSS] Drag-and-drop to reference a stylesheet
https://bugs.eclipse.org/bugs/show_bug.cgi?id=461432 Support drag-and-drop of CSS stylesheets onto diagrams. Change-Id: I45c424b39ae60856a389639653f1d8140cdfadcb
Diffstat (limited to 'plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties')
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF5
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/plugin.xml6
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dnd/StyleSheetDropStrategy.java122
3 files changed, 132 insertions, 1 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF
index b45bac62e71..a7ce30ac3bf 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF
@@ -24,7 +24,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.1.0",
org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.1.0",
org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.1.0",
- org.eclipse.e4.ui.css.core;bundle-version="0.10.0"
+ org.eclipse.e4.ui.css.core;bundle-version="0.10.0",
+ org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="1.1.0",
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.1.0"
Bundle-Vendor: Eclipse Modeling Project
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.0.qualifier
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/plugin.xml b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/plugin.xml
index 9875e752e98..dabd3c96f79 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/plugin.xml
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/plugin.xml
@@ -124,4 +124,10 @@
</enabledWhen>
</page>
</extension>
+ <extension
+ point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy">
+ <strategy
+ strategy="org.eclipse.papyrus.infra.gmfdiag.css.properties.dnd.StyleSheetDropStrategy">
+ </strategy>
+ </extension>
</plugin>
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dnd/StyleSheetDropStrategy.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dnd/StyleSheetDropStrategy.java
new file mode 100644
index 00000000000..1b4bde35a18
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dnd/StyleSheetDropStrategy.java
@@ -0,0 +1,122 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.dnd;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSStyles;
+import org.eclipse.papyrus.infra.gmfdiag.css.properties.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding.AddCSSStyleSheetCommand;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
+import org.eclipse.swt.graphics.Image;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Strategy for dropping CSS resources onto a diagram to add a stylesheet reference.
+ */
+public class StyleSheetDropStrategy extends TransactionalDropStrategy {
+ public static final String ID = Activator.PLUGIN_ID + ".drop"; //$NON-NLS-1$
+
+ public StyleSheetDropStrategy() {
+ super();
+ }
+
+ public String getLabel() {
+ return "Add Stylesheet Reference";
+ }
+
+ public String getDescription() {
+ return "Adds a stylesheet to the diagram by reference to the dropped CSS resource";
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public String getID() {
+ return ID;
+ }
+
+ public int getPriority() {
+ return 0;
+ }
+
+ @Override
+ protected Command doGetCommand(Request request, EditPart targetEditPart) {
+ Command result = null;
+
+ // Only diagram supports stylesheet reference
+ View targetView = NotationHelper.findView(targetEditPart);
+ targetView = (targetView != null) ? targetView.getDiagram() : targetView;
+ if (targetView != null) {
+ // The DropObjectsRequest has only EObjects if it contains anything, so go directly to the source
+ List<?> objects;
+ ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
+ if (selection instanceof IStructuredSelection) {
+ objects = ((IStructuredSelection) selection).toList();
+ } else {
+ objects = Collections.emptyList();
+ }
+
+ List<IFile> cssFiles = Lists.newArrayListWithCapacity(objects.size());
+ for (Object next : objects) {
+ IFile file = AdapterUtils.adapt(next, IFile.class, null);
+ if ((file != null) && "css".equals(file.getFileExtension())) {
+ cssFiles.add(file);
+ } else {
+ // All-or-nothing drop
+ cssFiles.clear();
+ break;
+ }
+ }
+
+ if (!cssFiles.isEmpty()) {
+ CompoundCommand compound = new CompoundCommand(getLabel());
+ TransactionalEditingDomain domain = getTransactionalEditingDomain(targetEditPart);
+ for (IFile next : cssFiles) {
+ StyleSheetReference ref = StylesheetsFactory.eINSTANCE.createStyleSheetReference();
+ ref.setPath(next.getFullPath().toString());
+ AddCSSStyleSheetCommand command = new AddCSSStyleSheetCommand(domain, targetView,
+ CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY,
+ NotationPackage.Literals.EOBJECT_LIST_VALUE_STYLE, NotationPackage.Literals.EOBJECT_LIST_VALUE_STYLE__EOBJECT_LIST_VALUE,
+ ref);
+ compound.add(EMFtoGEFCommandWrapper.wrap(command));
+ }
+
+ result = compound.unwrap();
+ }
+ }
+
+ return result;
+ }
+
+}

Back to the top