summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-03-07 09:26:20 (EST)
committerGabriel Pascual2014-03-07 09:28:36 (EST)
commitfe4f416b6ec4de6a8314814efe40fb8d3ba56c88 (patch)
tree3bc2b2f94a73d90b44c90bef86cad7c397d65553
parentbc83ec570969c642449d48b3085fdbdbca033e68 (diff)
downloadorg.eclipse.papyrus-fe4f416b6ec4de6a8314814efe40fb8d3ba56c88.zip
org.eclipse.papyrus-fe4f416b6ec4de6a8314814efe40fb8d3ba56c88.tar.gz
org.eclipse.papyrus-fe4f416b6ec4de6a8314814efe40fb8d3ba56c88.tar.bz2
429643: [CSS] Project shall have a property for associating project
style sheets https://bugs.eclipse.org/bugs/show_bug.cgi?id=429643 - Add functions to manage style sheets list Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF96
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java357
2 files changed, 391 insertions, 62 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
index c8f2154..8b67d96 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
@@ -1,46 +1,50 @@
-Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.e4.ui.css.core;bundle-version="0.10.0",
- org.eclipse.emf.ecore;bundle-version="2.8.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
- org.w3c.css.sac;bundle-version="1.3.1",
- org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
- org.eclipse.core.databinding;bundle-version="1.4.1",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.css.model;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.notation.edit;bundle-version="1.7.0",
- org.w3c.dom.svg;bundle-version="1.1.0"
-Export-Package: org.eclipse.papyrus.infra.gmfdiag.css,
- org.eclipse.papyrus.infra.gmfdiag.css.converters,
- org.eclipse.papyrus.infra.gmfdiag.css.dom,
- org.eclipse.papyrus.infra.gmfdiag.css.engine,
- org.eclipse.papyrus.infra.gmfdiag.css.engine.enginecopy,
- org.eclipse.papyrus.infra.gmfdiag.css.handler,
- org.eclipse.papyrus.infra.gmfdiag.css.helper,
- org.eclipse.papyrus.infra.gmfdiag.css.listener,
- org.eclipse.papyrus.infra.gmfdiag.css.lists,
- org.eclipse.papyrus.infra.gmfdiag.css.notation,
- org.eclipse.papyrus.infra.gmfdiag.css.preferences,
- org.eclipse.papyrus.infra.gmfdiag.css.provider,
- org.eclipse.papyrus.infra.gmfdiag.css.resource,
- org.eclipse.papyrus.infra.gmfdiag.css.service,
- org.eclipse.papyrus.infra.gmfdiag.css.style.impl,
- org.eclipse.papyrus.infra.gmfdiag.css.theme
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.0.qualifier
-Bundle-Name: %pluginName
-Bundle-Localization: plugin
-Bundle-ManifestVersion: 2
-Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.css.Activator
-Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.css;singleton:=
- true
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.e4.ui.css.core;bundle-version="0.10.0",
+ org.eclipse.emf.ecore;bundle-version="2.8.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
+ org.w3c.css.sac;bundle-version="1.3.1",
+ org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
+ org.eclipse.core.databinding;bundle-version="1.4.1",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.css.model;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.notation.edit;bundle-version="1.7.0",
+ org.w3c.dom.svg;bundle-version="1.1.0",
+ org.eclipse.emf.edit.ui,
+ org.eclipse.papyrus.views.properties,
+ org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.2.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0"
+Export-Package: org.eclipse.papyrus.infra.gmfdiag.css,
+ org.eclipse.papyrus.infra.gmfdiag.css.converters,
+ org.eclipse.papyrus.infra.gmfdiag.css.dom,
+ org.eclipse.papyrus.infra.gmfdiag.css.engine,
+ org.eclipse.papyrus.infra.gmfdiag.css.engine.enginecopy,
+ org.eclipse.papyrus.infra.gmfdiag.css.handler,
+ org.eclipse.papyrus.infra.gmfdiag.css.helper,
+ org.eclipse.papyrus.infra.gmfdiag.css.listener,
+ org.eclipse.papyrus.infra.gmfdiag.css.lists,
+ org.eclipse.papyrus.infra.gmfdiag.css.notation,
+ org.eclipse.papyrus.infra.gmfdiag.css.preferences,
+ org.eclipse.papyrus.infra.gmfdiag.css.provider,
+ org.eclipse.papyrus.infra.gmfdiag.css.resource,
+ org.eclipse.papyrus.infra.gmfdiag.css.service,
+ org.eclipse.papyrus.infra.gmfdiag.css.style.impl,
+ org.eclipse.papyrus.infra.gmfdiag.css.theme
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.0.qualifier
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.css.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.css;singleton:=
+ true
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+
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
index 93a7a46..408fc66 100644
--- 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
@@ -12,7 +12,10 @@
package org.eclipse.papyrus.infra.gmfdiag.css.property;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -21,12 +24,38 @@ 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.EStructuralFeature;
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.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.emf.providers.EMFContentProvider;
+import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
-import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsFactoryImpl;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage;
+import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog;
+import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector;
+import org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPropertyPage;
@@ -44,7 +73,24 @@ import org.eclipse.ui.dialogs.PropertyPage;
*/
public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
- private Resource resource;
+ /** Preference resource of project to load and save. */
+ private Resource resource = null;
+
+ /** Style sheets model used to manage style sheets list as container. */
+ private ModelStyleSheets modelStyleSheets = null;
+
+ /** Content provider which used for different displays. */
+ private IContentProvider contentProvider = null;
+
+ /** Label provider which used for different displays. */
+ private ILabelProvider labelProvider = null;
+
+ /** Viewer for style sheets list. */
+ private TreeViewer styleSheetsViewer = null;
+
+ /** Button to delete style sheets in project preferences. */
+ private Button removeButton = null;
+
/**
* Default Constructor.
@@ -53,6 +99,7 @@ public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchP
public StyleSheetsPropertyPage() {
//This preference is stored with EMF format : .settings/stylesheets.xmi
setPreferenceStore(null);
+ noDefaultAndApplyButton();
}
@@ -61,15 +108,15 @@ public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchP
/**
* Get Style sheets model file to manage preference.
*
- * @return a new style sheets model or the exiting one
+ * @return a new style sheets list or the existing one
*/
- private ModelStyleSheets getProjectStylesheets() {
+ private EList<EObject> getProjectStylesheets() {
//Get selected project
Object pageElement = getElement().getAdapter(IProject.class);
//Initialize preferences data
ResourceSet resourceSet = new ResourceSetImpl();
- ModelStyleSheets rootModel = null;
+ EList<EObject> styleSheetsList = null;
//Check if element is a project
if(pageElement instanceof IProject) {
@@ -86,24 +133,20 @@ public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchP
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);
- }
+ resource = resourceSet.getResource(URI.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true), true);
+ styleSheetsList = resource.getContents();
+
} else {
//Create default preference file
resource = resourceSet.createResource(URI.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true));
- rootModel = StylesheetsFactoryImpl.eINSTANCE.createModelStyleSheets();
- resource.getContents().add(rootModel);
-
+ styleSheetsList = resource.getContents();
}
}
}
- return rootModel;
+ return styleSheetsList;
}
/**
@@ -115,8 +158,244 @@ public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchP
*/
@Override
protected Control createContents(Composite parent) {
- getProjectStylesheets();
- return null;
+
+ // Create the container composite
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout containerLayout = new GridLayout(2, false);
+ container.setLayout(containerLayout);
+
+ // Initialize data and providers fro page
+ initializeDataPage();
+ initializeProviders();
+
+ // Create different components
+ createStyleSheetsPageViewer(container);
+ createStyleSheetsPageButtons(container);
+
+ //Update state buttons
+ updateButton();
+
+ return container;
+ }
+
+
+
+
+ /**
+ * Initialize preference page.
+ */
+ private void initializeDataPage() {
+
+ EList<EObject> stylesheetsModel = getProjectStylesheets();
+ modelStyleSheets = (ModelStyleSheets)StylesheetsPackage.eINSTANCE.getEFactoryInstance().create(StylesheetsPackage.Literals.MODEL_STYLE_SHEETS);
+ modelStyleSheets.getStylesheets();
+ List<EObject> mirrorList = new ArrayList<EObject>();
+ mirrorList.addAll(stylesheetsModel);
+
+ for(EObject object : mirrorList) {
+
+ if(object instanceof StyleSheet) {
+ modelStyleSheets.getStylesheets().add((StyleSheet)object);
+ }
+ }
+
+
+
+ }
+
+
+
+
+ /**
+ * Initialize the different providers to display style sheets list.
+ */
+ private void initializeProviders() {
+
+ contentProvider = new EMFContentProvider(modelStyleSheets, StylesheetsPackage.eINSTANCE.getModelStyleSheets_Stylesheets()) {
+
+ @Override
+ protected IStructuredContentProvider getSemanticProvider(final EObject editedEObject, final EStructuralFeature feature) {
+
+ // Use a standard content provider
+ return new AbstractStaticContentProvider() {
+
+ public Object[] getElements() {
+ List<Object> result = new LinkedList<Object>();
+ if(editedEObject instanceof ModelStyleSheets) {
+ result.addAll(modelStyleSheets.getStylesheets());
+ }
+ return result.toArray();
+ }
+ };
+ }
+ };
+
+ labelProvider = new StylesheetsModelLabelProvider();
+ }
+
+
+
+
+ /**
+ * Create viewer to display content of style sheets model.
+ *
+ * @param parent
+ * Parent composite where compound will added
+ */
+ private void createStyleSheetsPageViewer(Composite parent) {
+
+
+ // Set layout and behavior to tree viewer
+ styleSheetsViewer = new TreeViewer(parent);
+ styleSheetsViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ styleSheetsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateButton();
+
+ }
+
+
+ });
+ styleSheetsViewer.setContentProvider(contentProvider);
+ styleSheetsViewer.setLabelProvider(labelProvider);
+ styleSheetsViewer.setInput(modelStyleSheets);
+ }
+
+
+
+
+ /**
+ * Create buttons which are associated with viewer.
+ *
+ * @param parent
+ * Parent composite where compound will added
+ */
+ private void createStyleSheetsPageButtons(Composite parent) {
+
+ //Build composite which contains buttons
+ Composite buttonsComposite = new Composite(parent, SWT.NONE);
+ buttonsComposite.setLayout(new GridLayout());
+ buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+
+
+ //Add button
+ Button addButton = new Button(buttonsComposite, SWT.PUSH);
+ addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ addButton.setImage(Activator.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "/icons/Add_12x12.gif").createImage());
+ addButton.addSelectionListener(new SelectionListener() {
+
+ /**
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ *
+ * @param e
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ ReferenceSelector selector = new ReferenceSelector(true);
+ selector.setContentProvider((IStaticContentProvider)contentProvider);
+ selector.setLabelProvider(labelProvider);
+
+ // Use common component for add dialog and parameterize it
+ MultipleValueSelectorDialog vDialog = new MultipleValueSelectorDialog(getShell(), selector, "CSS Style Sheet");
+ vDialog.setContextElement(modelStyleSheets);
+ vDialog.setLabelProvider(labelProvider);
+ vDialog.setFactory(new EcorePropertyEditorFactory(StylesheetsPackage.Literals.MODEL_STYLE_SHEETS__STYLESHEETS));
+
+ // Handle dialog result
+ int result = vDialog.open();
+ if(result == Dialog.OK) {
+
+ Object[] resultArray = vDialog.getResult();
+ if(resultArray != null) {
+ refreshStyleSheets(resultArray);
+ }
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ //Nothing to do
+ }
+ });
+
+ removeButton = new Button(buttonsComposite, SWT.PUSH);
+ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ removeButton.setImage(Activator.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "/icons/Delete_12x12.gif").createImage());
+ removeButton.addSelectionListener(new SelectionListener() {
+
+ /**
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ *
+ * @param e
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ISelection selection = styleSheetsViewer.getSelection();
+ if(selection instanceof IStructuredSelection) {
+
+ // Handle selection
+ Object firstElement = ((IStructuredSelection)selection).getFirstElement();
+ if(firstElement instanceof StyleSheet) {
+ modelStyleSheets.getStylesheets().remove(firstElement);
+ }
+
+ // Refresh viewer
+ styleSheetsViewer.setInput(modelStyleSheets);
+
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ *
+ * @param e
+ */
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing to do
+
+ }
+ });
+ }
+
+ /**
+ * Fill style sheets viewer with selected style sheets.
+ *
+ * @param result
+ * Result from dialog selection
+ */
+ protected void refreshStyleSheets(Object[] result) {
+
+ // Add selected CSS style sheets
+ for(Object object : result) {
+
+ //Check if object is a style sheet
+ if(object instanceof StyleSheet) {
+ modelStyleSheets.getStylesheets().add((StyleSheet)object);
+
+ }
+ }
+
+ // Refresh viewer
+ styleSheetsViewer.setInput(modelStyleSheets);
+ }
+
+
+
+
+ /**
+ * Update state buttons.
+ */
+ protected void updateButton() {
+ ISelection selection = styleSheetsViewer.getSelection();
+
+ removeButton.setEnabled(!selection.isEmpty());
+
+
}
/**
@@ -130,6 +409,8 @@ public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchP
boolean performOK = false;
try {
+ resource.getContents().addAll(modelStyleSheets.getStylesheets());
+
// Save preference file
resource.save(Collections.EMPTY_MAP);
performOK = true;
@@ -140,4 +421,48 @@ public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchP
return performOK;
}
+
+
+ /**
+ *
+ * Label provider for style sheets list in different displays.
+ *
+ * @author gpascual
+ *
+ */
+ public class StylesheetsModelLabelProvider extends EMFLabelProvider {
+
+ /**
+ * Default constructor.
+ *
+ */
+ public StylesheetsModelLabelProvider() {
+ super();
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public String getText(Object element) {
+ String text = "";
+
+ if(element instanceof StyleSheetReference) {
+ text = ((StyleSheetReference)element).getPath();
+ } else if(element instanceof EmbeddedStyleSheet) {
+ text = ((EmbeddedStyleSheet)element).getLabel();
+ }
+
+ return text;
+ }
+
+
+
+ }
+
+
+
}