Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org')
-rw-r--r--plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/Activator.java69
-rw-r--r--plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/factory/CSSExtensionFactory.java115
-rw-r--r--plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElement.java74
-rw-r--r--plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElementFactory.java36
4 files changed, 294 insertions, 0 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/Activator.java b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/Activator.java
new file mode 100644
index 00000000000..dd0c37150c8
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/Activator.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.export;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.gmfdiag.css.export"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/factory/CSSExtensionFactory.java b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/factory/CSSExtensionFactory.java
new file mode 100644
index 00000000000..c3960b0a6aa
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/factory/CSSExtensionFactory.java
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.export.factory;
+
+import java.io.IOException;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.papyrus.customization.factory.FileBasedExtensionFactory;
+import org.eclipse.papyrus.customization.model.customizationplugin.CustomizableElement;
+import org.eclipse.papyrus.customization.model.customizationplugin.FileBasedCustomizableElement;
+import org.eclipse.papyrus.customization.plugin.PluginEditor;
+import org.eclipse.papyrus.infra.gmfdiag.css.export.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.css.export.csscustomization.CSSStylesheet;
+import org.eclipse.papyrus.infra.gmfdiag.css.export.csscustomization.CsscustomizationPackage;
+import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager;
+import org.w3c.dom.Element;
+
+
+public class CSSExtensionFactory extends FileBasedExtensionFactory {
+
+ protected final static String stylesheetContribution = "stylesheet"; //$NON-NLS-1$ //From oep.infra.gmfdiag.css.theme extension point
+
+ protected final static String themeDefinition = "themeDefinition"; //$NON-NLS-1$ //From oep.infra.gmfdiag.css.theme extension point
+
+ protected final static String themeIcon = "icon"; //$NON-NLS-1$ //From oep.infra.gmfdiag.css.theme extension point
+
+ protected final static String themeLabel = "label"; //$NON-NLS-1$ //From oep.infra.gmfdiag.css.theme extension point
+
+ protected final static String themeId = "id"; //$NON-NLS-1$ //From oep.infra.gmfdiag.css.theme extension point
+
+ public CSSExtensionFactory() {
+ super("CSS Theme", ThemeManager.EXTENSION_ID, "stylesheetPath", "themeContribution", true);
+ }
+
+ public EClass getCustomizableElementClass() {
+ return CsscustomizationPackage.eINSTANCE.getCSSStylesheet();
+ }
+
+ @Override
+ public void addElement(CustomizableElement element, PluginEditor editor) {
+ super.addElement(element, editor);
+ }
+
+ @Override
+ protected String getTargetPath(FileBasedCustomizableElement element) {
+ return "style/" + getFileName(element); //$NON-NLS-1$
+ }
+
+ @Override
+ protected Element createExtension(FileBasedCustomizableElement element, PluginEditor editor) {
+ Element themeContributionElement = null;
+ if(element instanceof CSSStylesheet) {
+ //Override the super implementation: The extension point structure has
+ //one more level than the super-implementation (css_theme > themeContribution > stylesheet)
+ CSSStylesheet stylesheetElement = (CSSStylesheet)element;
+
+ Element extension = editor.getPluginEditor().addExtension(extensionPoint); //cssTheme
+
+ //Optional: Create & configure the themeDefinition (New Theme)
+ if(ThemeManager.instance.getTheme(stylesheetElement.getTheme()) == null) {
+ createNewThemeExtension(stylesheetElement, editor, extension);
+ }
+
+ //Required: Create the Theme contribution
+ themeContributionElement = editor.getPluginEditor().addChild(extension, fileElementName);
+ Element cssContributionElement = editor.getPluginEditor().addChild(themeContributionElement, stylesheetContribution);
+
+ editor.getPluginEditor().setAttribute(cssContributionElement, fileAttributeName, getTargetPath(stylesheetElement));
+
+ //Configure the themeContribution
+ themeContributionElement.setAttribute(themeId, stylesheetElement.getTheme());
+ }
+
+ return themeContributionElement;
+ }
+
+ protected Element createNewThemeExtension(CSSStylesheet stylesheetElement, PluginEditor editor, Element extension) {
+ Element themeDefinitionElement = editor.getPluginEditor().addChild(extension, themeDefinition);
+
+ String iconPath = stylesheetElement.getIcon();
+ if(iconPath == null) {
+ throw new IllegalArgumentException("Icon path should not be empty");
+ }
+
+ String targetIconPath = getFileName(getTargetIconPath(stylesheetElement));
+ if(targetIconPath == null || targetIconPath.equals("")) {
+ throw new IllegalArgumentException("Icon path should not be empty");
+ }
+
+ try {
+ copyFile(iconPath, targetIconPath, editor);
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+
+ editor.getPluginEditor().setAttribute(themeDefinitionElement, themeId, stylesheetElement.getTheme());
+ editor.getPluginEditor().setAttribute(themeDefinitionElement, themeIcon, targetIconPath);
+ editor.getPluginEditor().setAttribute(themeDefinitionElement, themeLabel, stylesheetElement.getLabel());
+
+ return themeDefinitionElement;
+ }
+
+ protected String getTargetIconPath(CSSStylesheet stylesheetElement) {
+ return "icons/" + getFileName(stylesheetElement.getIcon());
+ }
+}
diff --git a/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElement.java b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElement.java
new file mode 100644
index 00000000000..08a46db9587
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElement.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.export.modelelement;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.gmfdiag.css.export.csscustomization.CsscustomizationPackage;
+import org.eclipse.papyrus.infra.gmfdiag.css.theme.Theme;
+import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager;
+import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager.EmptyTheme;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.StaticContentProvider;
+import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement;
+
+
+public class CSSExportModelElement extends EMFModelElement {
+
+ /**
+ *
+ * Constructs a new CSSExportModelElement for the given EObject
+ *
+ * @param source
+ */
+ public CSSExportModelElement(EObject source) {
+ super(source);
+ }
+
+ /**
+ *
+ * Constructs a new CSSExportModelElement for the given EObject and Editing Domain
+ *
+ * @param source
+ * @param domain
+ */
+ public CSSExportModelElement(EObject source, EditingDomain domain) {
+ super(source, domain);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IStaticContentProvider getContentProvider(String propertyPath) {
+ EStructuralFeature feature = getFeature(propertyPath);
+ if(feature == CsscustomizationPackage.eINSTANCE.getCSSStylesheet_Theme()) {
+ List<Theme> allThemes = ThemeManager.instance.getThemes();
+ String[] themeIds = new String[allThemes.size() - 1]; //-1 to ignore the EmptyTheme
+
+ int i = 0;
+ for(Theme theme : allThemes) {
+ if(theme != EmptyTheme.instance) {
+ themeIds[i++] = theme.getId();
+ }
+ }
+
+ return new StaticContentProvider(themeIds);
+ }
+
+ return super.getContentProvider(propertyPath);
+ }
+
+}
diff --git a/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElementFactory.java b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElementFactory.java
new file mode 100644
index 00000000000..4aa132ea1a5
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.infra.gmfdiag.css.export/src/org/eclipse/papyrus/infra/gmfdiag/css/export/modelelement/CSSExportModelElementFactory.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.export.modelelement;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.export.Activator;
+import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory;
+
+
+public class CSSExportModelElementFactory implements ModelElementFactory {
+
+ public ModelElement createFromSource(Object sourceElement, DataContextElement context) {
+ EObject source = EMFHelper.getEObject(sourceElement);
+ if(source == null) {
+ Activator.log.warn("Unable to resolve the selected element to an EObject"); //$NON-NLS-1$
+ return null;
+ }
+
+ EditingDomain domain = EMFHelper.resolveEditingDomain(source);
+ return new CSSExportModelElement(source, domain);
+ }
+
+}

Back to the top