summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-03-05 09:45:05 (EST)
committerGabriel Pascual2014-03-05 09:45:05 (EST)
commitbc83ec570969c642449d48b3085fdbdbca033e68 (patch)
treed61b4aa5335c8859683c8c0082079f55192a6bb9
parent928030220ebf333020a828bc5ba753d99dc8d76c (diff)
downloadorg.eclipse.papyrus-bc83ec570969c642449d48b3085fdbdbca033e68.zip
org.eclipse.papyrus-bc83ec570969c642449d48b3085fdbdbca033e68.tar.gz
org.eclipse.papyrus-bc83ec570969c642449d48b3085fdbdbca033e68.tar.bz2
429643: [CSS] Project shall have a property for associating style sheets
https://bugs.eclipse.org/bugs/show_bug.cgi?id=429643 - Add property page - Mecanism to create or load property file (Style sheets model) Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml179
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java143
2 files changed, 239 insertions, 83 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml
index db70482..5ee6e87 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml
@@ -1,84 +1,97 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension-point id="theme" name="CSS Theme" schema="schema/theme.exsd"/>
- <extension-point id="markertopseudoselectormappingprovider" name="MarkerToPseudoSelectorMappingProvider" schema="schema/markertopseudoselectormappingprovider.exsd"/>
- <extension-point id="domElementAdapter" name="domElementAdapter" schema="schema/domElementAdapter.exsd"/>
- <extension point="org.eclipse.emf.ecore.factory_override">
- <factory
- class="org.eclipse.papyrus.infra.gmfdiag.css.factory.CSSNotationFactory"
- uri="http://www.eclipse.org/gmf/runtime/1.0.2/notation">
- </factory>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.emf.appearance.styleProvider">
- <styleprovider
- priority="40"
- styleProvider="org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSAppearanceProvider">
- </styleprovider>
- </extension>
- <extension
- point="org.eclipse.ui.preferencePages">
- <page
- category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
- class="org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferencesPage"
- id="org.eclipse.papyrus.infra.gmfdiag.css.theme"
- name="CSS Theme">
- </page>
- </extension>
- <extension
- point="org.eclipse.core.runtime.preferences">
- <initializer
- class="org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferenceInitializer">
- </initializer>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.gmfdiag.common.initializeView">
- <initializeView
- initializeView="org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSThemeInitializer">
- </initializeView>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.core.model">
- <model
- classname="org.eclipse.papyrus.infra.gmfdiag.css.resource.CSSNotationModel"
- description="A model for Notation resources with CSS support">
- </model>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.services.markerlistener.markereventlistener">
- <listener
- class="org.eclipse.papyrus.infra.gmfdiag.css.service.CssMarkerEventManagerService"></listener>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.core.service">
- <service
- classname="org.eclipse.papyrus.infra.gmfdiag.css.service.CssMarkerEventManagerService"
- priority="1"
- startKind="lazy">
- </service>
- </extension>
- <extension
- point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
- <editpolicyProvider
- class="org.eclipse.papyrus.infra.gmfdiag.css.editpolicies.MarkerEventListenerEditPolicyProvider">
- <Priority
- name="Lowest">
- </Priority>
- </editpolicyProvider>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.core.service">
- <service
- classname="org.eclipse.papyrus.infra.gmfdiag.css.service.MarkerToPseudoSelectorMappingService"
- priority="1"
- startKind="lazy">
- </service>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.gmfdiag.common.svgPostProcessors">
- <postProcessor
- implementation="org.eclipse.papyrus.infra.gmfdiag.css.CssSvgPostProcessor">
- </postProcessor>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="theme" name="CSS Theme" schema="schema/theme.exsd"/>
+ <extension-point id="markertopseudoselectormappingprovider" name="MarkerToPseudoSelectorMappingProvider" schema="schema/markertopseudoselectormappingprovider.exsd"/>
+ <extension-point id="domElementAdapter" name="domElementAdapter" schema="schema/domElementAdapter.exsd"/>
+ <extension point="org.eclipse.emf.ecore.factory_override">
+ <factory
+ class="org.eclipse.papyrus.infra.gmfdiag.css.factory.CSSNotationFactory"
+ uri="http://www.eclipse.org/gmf/runtime/1.0.2/notation">
+ </factory>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.emf.appearance.styleProvider">
+ <styleprovider
+ priority="40"
+ styleProvider="org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSAppearanceProvider">
+ </styleprovider>
</extension>
-</plugin>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
+ class="org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferencesPage"
+ id="org.eclipse.papyrus.infra.gmfdiag.css.theme"
+ name="CSS Theme">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferenceInitializer">
+ </initializer>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.gmfdiag.common.initializeView">
+ <initializeView
+ initializeView="org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSThemeInitializer">
+ </initializeView>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.core.model">
+ <model
+ classname="org.eclipse.papyrus.infra.gmfdiag.css.resource.CSSNotationModel"
+ description="A model for Notation resources with CSS support">
+ </model>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.markerlistener.markereventlistener">
+ <listener
+ class="org.eclipse.papyrus.infra.gmfdiag.css.service.CssMarkerEventManagerService"></listener>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.core.service">
+ <service
+ classname="org.eclipse.papyrus.infra.gmfdiag.css.service.CssMarkerEventManagerService"
+ priority="1"
+ startKind="lazy">
+ </service>
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
+ <editpolicyProvider
+ class="org.eclipse.papyrus.infra.gmfdiag.css.editpolicies.MarkerEventListenerEditPolicyProvider">
+ <Priority
+ name="Lowest">
+ </Priority>
+ </editpolicyProvider>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.core.service">
+ <service
+ classname="org.eclipse.papyrus.infra.gmfdiag.css.service.MarkerToPseudoSelectorMappingService"
+ priority="1"
+ startKind="lazy">
+ </service>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.gmfdiag.common.svgPostProcessors">
+ <postProcessor
+ implementation="org.eclipse.papyrus.infra.gmfdiag.css.CssSvgPostProcessor">
+ </postProcessor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ category="org.eclipse.papyrus.infra.gmfdiag.preferences.properties.generalcategory"
+ class="org.eclipse.papyrus.infra.gmfdiag.css.property.StyleSheetsPropertyPage"
+ id="org.eclipse.papyrus.infra.gmfdiag.css.stylesheets"
+ name="Style sheets">
+ <enabledWhen>
+ <adapt
+ type="org.eclipse.core.resources.IProject">
+ </adapt></enabledWhen>
+ </page>
+ </extension>
+</plugin>
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java
new file mode 100644
index 0000000..93a7a46
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java
@@ -0,0 +1,143 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.property;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.papyrus.infra.gmfdiag.css.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsFactoryImpl;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+
+
+/**
+ * Preference page to associate set of style sheets to Papyrus project.
+ * <p>
+ * The preference is stored in a file with EMF format. The target is file .settings/stylesheets.xmi
+ * </p>
+ *
+ * @author gpascual
+ */
+public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
+
+ private Resource resource;
+
+ /**
+ * Default Constructor.
+ *
+ */
+ public StyleSheetsPropertyPage() {
+ //This preference is stored with EMF format : .settings/stylesheets.xmi
+ setPreferenceStore(null);
+ }
+
+
+
+
+ /**
+ * Get Style sheets model file to manage preference.
+ *
+ * @return a new style sheets model or the exiting one
+ */
+ private ModelStyleSheets getProjectStylesheets() {
+ //Get selected project
+ Object pageElement = getElement().getAdapter(IProject.class);
+
+ //Initialize preferences data
+ ResourceSet resourceSet = new ResourceSetImpl();
+ ModelStyleSheets rootModel = null;
+
+ //Check if element is a project
+ if(pageElement instanceof IProject) {
+ // Build path of preference file
+ ProjectScope pageProject = new ProjectScope((IProject)pageElement);
+ IPath preferencePath = pageProject.getLocation().append("stylesheets.xmi");
+
+ // Check path is valid
+ if(preferencePath != null) {
+
+ // Verify presence of file in project
+ IPath projectRelativePath = preferencePath.makeRelativeTo(((IProject)pageElement).getLocation());
+ IFile preferenceFile = ((IProject)pageElement).getFile(projectRelativePath);
+ if(preferenceFile.exists()) {
+
+ //Load existing preference file
+ resource = resourceSet.getResource(URI.createURI(preferenceFile.getFullPath().toOSString()), true);
+ EList<EObject> resourceContents = resource.getContents();
+ if(!resourceContents.isEmpty() && resourceContents.get(0) instanceof ModelStyleSheets) {
+ rootModel = (ModelStyleSheets)resourceContents.get(0);
+ }
+
+ } else {
+
+ //Create default preference file
+ resource = resourceSet.createResource(URI.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true));
+ rootModel = StylesheetsFactoryImpl.eINSTANCE.createModelStyleSheets();
+ resource.getContents().add(rootModel);
+
+ }
+ }
+ }
+
+ return rootModel;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ * @return
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ getProjectStylesheets();
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.preference.PreferencePage#performOk()
+ *
+ * @return
+ */
+ @Override
+ public boolean performOk() {
+ boolean performOK = false;
+
+ try {
+ // Save preference file
+ resource.save(Collections.EMPTY_MAP);
+ performOK = true;
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+
+ return performOK;
+ }
+
+}