From 10466696bedf38656b765c50974e95678ce25cb5 Mon Sep 17 00:00:00 2001 From: Gabriel Pascual Date: Fri, 18 Apr 2014 17:00:48 +0200 Subject: 429643: [CSS] Project shall have a property for associating project style sheets https://bugs.eclipse.org/bugs/show_bug.cgi?id=429643 - Move project property page file and contribution to oep.infra.gmfdiag.css.properties for a dependency problem - Add actions on project property page style sheets list( up, down, edit) Change-Id: Ib806a5d43bc5f8f3b85932eed216b8bb3dce8051 Signed-off-by: Gabriel Pascual --- .../build.properties | 19 +- .../messages.properties | 2 + .../plugin.xml | 47 +- .../gmfdiag/css/properties/messages/Messages.java | 33 ++ .../property/StyleSheetsPropertyPage.java | 603 +++++++++++++++++++++ .../META-INF/MANIFEST.MF | 103 ++-- .../messages.properties | 2 - .../plugin.xml | 13 - .../infra/gmfdiag/css/messages/Messages.java | 33 -- .../css/property/StyleSheetsPropertyPage.java | 493 ----------------- 10 files changed, 729 insertions(+), 619 deletions(-) create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/messages.properties create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/messages/Messages.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/property/StyleSheetsPropertyPage.java delete mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/messages.properties delete mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/messages/Messages.java delete mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/build.properties b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/build.properties index 2fefe2c0e4a..ab1e8891950 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/build.properties +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/build.properties @@ -1,9 +1,10 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - about.html,\ - model/,\ - icons/ -src.includes = about.html +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + about.html,\ + model/,\ + icons/,\ + messages.properties +src.includes = about.html diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/messages.properties b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/messages.properties new file mode 100644 index 00000000000..b4cac9de22c --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/messages.properties @@ -0,0 +1,2 @@ +StyleSheetsPropertyPage.preference.page.label=Add CSS style sheets on project properties to apply them to all models. +StyleSheetsPropertyPage.preference.page.title=CSS Style Sheet 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 651d763f968..ca63aef4b60 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 @@ -1,17 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/messages/Messages.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/messages/Messages.java new file mode 100644 index 00000000000..7969ceb969f --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/messages/Messages.java @@ -0,0 +1,33 @@ +/***************************************************************************** + * 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.properties.messages; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages { + + private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/property/StyleSheetsPropertyPage.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/property/StyleSheetsPropertyPage.java new file mode 100644 index 00000000000..2bee5b7dbc8 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/property/StyleSheetsPropertyPage.java @@ -0,0 +1,603 @@ +/***************************************************************************** + * 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.properties.property; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +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.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.gmfdiag.css.Activator; +import org.eclipse.papyrus.infra.gmfdiag.css.engine.ProjectCSSEngine; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.messages.Messages; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.provider.CSSStyleSheetLabelProvider; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; +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.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +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.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.dialogs.PropertyPage; +import org.eclipse.ui.plugin.AbstractUIPlugin; + + + +/** + * Preference page to associate set of style sheets to Papyrus project. + *

+ * The preference is stored in a file with EMF format. The target is file .settings/stylesheets.xmi + *

+ * + * @author gpascual + */ +public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { + + + /** Text for preference page label. */ + private static final String PREFERENCE_PAGE_LABEL = Messages.getString("StyleSheetsPropertyPage.preference.page.label"); //$NON-NLS-1$ + + /** Text for preference page title. */ + private static final String PREFERENCE_PAGE_TITLE = Messages.getString("StyleSheetsPropertyPage.preference.page.title"); //$NON-NLS-1$ + + /** Icon for delete button. */ + private static final Image DELETE_ICON = Activator.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "/icons/Delete_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Icon for add button. */ + private static final Image ADD_ICON = Activator.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "/icons/Add_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Icon for edit button. */ + private static final Image EDIT_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Edit_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Icon for up action button. */ + private static final Image UP_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Up_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Icon for down action button. */ + private static final Image DOWN_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Down_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Id for add button. */ + private static final int ADD_BUTTON_ID = 1; + + /** Id for delete button. */ + private static final int DELETE_BUTTON_ID = 2; + + /** Id for up button. */ + private static final int UP_BUTTON_ID = 3; + + /** Id for down button. */ + private static final int DOWN_BUTTON_ID = 4; + + /** Id for edit button. */ + private static final int EDIT_BUTTON_ID = 0; + + /** 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; + + /** Map of all buttons of property page. */ + private Map buttonsMap = new HashMap(); + + /** Editor factory to edit Style sheets */ + private ReferenceValueFactory editorFactory = new EcorePropertyEditorFactory(StylesheetsPackage.Literals.MODEL_STYLE_SHEETS__STYLESHEETS); + + /** + * Default Constructor. + * + */ + public StyleSheetsPropertyPage() { + //This preference is stored with EMF format : .settings/stylesheets.xmi + setPreferenceStore(null); + noDefaultAndApplyButton(); + } + + + /** + * Get Style sheets model file to manage preference. + * + * @return a new style sheets list or the existing one + */ + private EList getProjectStylesheets() { + //Get selected project + Object pageElement = getElement().getAdapter(IProject.class); + + //Initialize preferences data + ResourceSet resourceSet = new ResourceSetImpl(); + EList styleSheetsList = 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(ProjectCSSEngine.PROJECT_STYLESHEETS); + + // 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.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true), true); + styleSheetsList = resource.getContents(); + + + } else { + + //Create default preference file + resource = resourceSet.createResource(URI.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true)); + styleSheetsList = resource.getContents(); + } + } + } + + return styleSheetsList; + } + + /** + * + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + * + * @param parent + * @return + */ + @Override + protected Control createContents(Composite parent) { + + // Create the container composite + Composite container = new Composite(parent, SWT.NONE); + GridLayout containerLayout = new GridLayout(2, false); + container.setLayout(containerLayout); + + // Initialize data and providers for page + initializeDataPage(); + initializeProviders(); + + // Create different components + createLabelPage(container); + createStyleSheetsPageViewer(container); + createStyleSheetsPageButtons(container); + + //Update state buttons + updateButtons(); + + return container; + } + + + + + /** + * Create label for page. + * + * @param parent + * Parent composite where compound will added + */ + private void createLabelPage(Composite parent) { + Label labelPage = new Label(parent, SWT.NONE); + + GridData layoutData = new GridData(SWT.FILL); + layoutData.horizontalSpan = 2; + labelPage.setLayoutData(layoutData); + + labelPage.setText(PREFERENCE_PAGE_LABEL); + + } + + + /** + * Initialize preference page. + */ + private void initializeDataPage() { + + EList stylesheetsModel = getProjectStylesheets(); + modelStyleSheets = (ModelStyleSheets)StylesheetsPackage.eINSTANCE.getEFactoryInstance().create(StylesheetsPackage.Literals.MODEL_STYLE_SHEETS); + modelStyleSheets.getStylesheets(); + List mirrorList = new ArrayList(); + 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 result = new LinkedList(); + if(editedEObject instanceof ModelStyleSheets) { + result.addAll(modelStyleSheets.getStylesheets()); + } + return result.toArray(); + } + }; + } + }; + + labelProvider = new CSSStyleSheetLabelProvider(); + } + + + + + /** + * 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() { + + + public void selectionChanged(SelectionChangedEvent event) { + updateButtons(); + + } + + + }); + 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 all buttons + createButton(buttonsComposite, ADD_ICON, ADD_BUTTON_ID); + createButton(buttonsComposite, DELETE_ICON, DELETE_BUTTON_ID); + createButton(buttonsComposite, UP_ICON, UP_BUTTON_ID); + createButton(buttonsComposite, DOWN_ICON, DOWN_BUTTON_ID); + createButton(buttonsComposite, EDIT_ICON, EDIT_BUTTON_ID); + } + + /** + * Method to create button. + * + * @param parent + * Composite where will be added + * @param icon + * Icon for button + * @param id + * Id to identify button + */ + private void createButton(Composite parent, Image icon, int id) { + Button button = new Button(parent, SWT.PUSH); + button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + button.setData(new Integer(id)); + button.setImage(icon); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(((Integer)event.widget.getData()).intValue()); + } + }); + + buttonsMap.put(id, button); + } + + /** + * 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); + updateButtons(); + } + + + /** + * Method call when a button is pressed. + * + * @param buttonId + */ + protected void buttonPressed(int buttonId) { + switch(buttonId) { + case ADD_BUTTON_ID: + addAction(); + break; + case DELETE_BUTTON_ID: + deleteAction(); + break; + case DOWN_BUTTON_ID: + downAction(); + break; + case UP_BUTTON_ID: + upAction(); + break; + case EDIT_BUTTON_ID: + editAction(); + break; + default: + break; + } + } + + /** + * Action to edit selected style sheet. + */ + private void editAction() { + + ISelection selection = styleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedObject = ((IStructuredSelection)selection).getFirstElement(); + if(selectedObject instanceof StyleSheet) { + // Use editor factory + editorFactory.edit(buttonsMap.get(EDIT_BUTTON_ID), selectedObject); + } + } + + } + + + /** + * Action to move up a style sheet in list. + */ + private void upAction() { + // Handle selection to extract selected style sheet + ISelection selection = styleSheetsViewer.getSelection(); + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof StyleSheet) { + + // Get index of selected style sheet in list + EList stylesheetsList = modelStyleSheets.getStylesheets(); + int index = stylesheetsList.indexOf(selectedElement); + + // Check if selected style sheet is not at top of list + if(index > 0) { + stylesheetsList.move(--index, (StyleSheet)selectedElement); + styleSheetsViewer.setInput(stylesheetsList); + } + } + } + + } + + + /** + * Action to move down selected style sheet in list. + */ + private void downAction() { + // Handle selection to extract selected style sheet + ISelection selection = styleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof StyleSheet) { + + // Get index of selected style sheet in list + EList stylesheetsList = modelStyleSheets.getStylesheets(); + int index = stylesheetsList.indexOf(selectedElement); + + // Check if selected style sheet is not at bottom of list + if(index < stylesheetsList.size() - 1) { + stylesheetsList.move(++index, (StyleSheet)selectedElement); + styleSheetsViewer.setInput(stylesheetsList); + } + } + } + + } + + + /** + * Action to delete selected style sheet. + */ + private void deleteAction() { + 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); + + updateButtons(); + + } + } + + + /** + * Action to add a style sheet. + */ + private void addAction() { + 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, PREFERENCE_PAGE_TITLE); + vDialog.setContextElement(modelStyleSheets); + vDialog.setLabelProvider(labelProvider); + vDialog.setFactory(editorFactory); + + // Handle dialog result + int result = vDialog.open(); + if(result == Dialog.OK) { + + Object[] resultArray = vDialog.getResult(); + if(resultArray != null) { + refreshStyleSheets(resultArray); + } + } + + } + + + /** + * Update state buttons. + */ + protected void updateButtons() { + ISelection selection = styleSheetsViewer.getSelection(); + boolean enabled = !selection.isEmpty(); + for(int idButton : buttonsMap.keySet()) { + switch(idButton) { + case UP_BUTTON_ID: + case DOWN_BUTTON_ID: + EList stylesheets = modelStyleSheets.getStylesheets(); + buttonsMap.get(idButton).setEnabled(enabled && !stylesheets.isEmpty() && stylesheets.size() > 1); + break; + case EDIT_BUTTON_ID: + case DELETE_BUTTON_ID: + buttonsMap.get(idButton).setEnabled(enabled); + break; + + default: + break; + } + + } + + + + } + + /** + * + * @see org.eclipse.jface.preference.PreferencePage#performOk() + * + * @return + */ + @Override + public boolean performOk() { + boolean performOK = false; + + try { + resource.getContents().addAll(modelStyleSheets.getStylesheets()); + + // Save preference file + resource.save(Collections.EMPTY_MAP); + performOK = true; + } catch (IOException e) { + Activator.log.error(e); + } + + return performOK; + } + + + +} 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 0cc3eff533d..4790d3e81cf 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,52 +1,51 @@ -Manifest-Version: 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 -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.papyrus.infra.viewpoints.policy;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;bundle-version="1.0.0", - org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0", - org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0", - org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0" -Bundle-Vendor: %providerName -Bundle-ActivationPolicy: lazy -Bundle-Version: 1.0.0.qualifier -Bundle-Localization: plugin -Bundle-Name: %pluginName -Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.css.Activator -Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.css;singleton:= - true -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 - +Manifest-Version: 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 +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.papyrus.infra.viewpoints.policy;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.infra.services.labelprovider;bundle-version="1.0.0", + org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0", + org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0" +Bundle-Vendor: %providerName +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.0.0.qualifier +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.css.Activator +Bundle-ManifestVersion: 2 +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/messages.properties b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/messages.properties deleted file mode 100644 index b4cac9de22c..00000000000 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/messages.properties +++ /dev/null @@ -1,2 +0,0 @@ -StyleSheetsPropertyPage.preference.page.label=Add CSS style sheets on project properties to apply them to all models. -StyleSheetsPropertyPage.preference.page.title=CSS Style Sheet 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 5ee6e87c189..50f07fcf9be 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 @@ -81,17 +81,4 @@ implementation="org.eclipse.papyrus.infra.gmfdiag.css.CssSvgPostProcessor"> - - - - - - - diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/messages/Messages.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/messages/Messages.java deleted file mode 100644 index 81e9dfa18ba..00000000000 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/messages/Messages.java +++ /dev/null @@ -1,33 +0,0 @@ -/***************************************************************************** - * 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.messages; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class Messages { - - private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); - - private Messages() { - } - - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } -} 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 deleted file mode 100644 index d7d8bf42b5d..00000000000 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/property/StyleSheetsPropertyPage.java +++ /dev/null @@ -1,493 +0,0 @@ -/***************************************************************************** - * 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.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; -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.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.messages.Messages; -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.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.swt.widgets.Label; -import org.eclipse.ui.IWorkbenchPropertyPage; -import org.eclipse.ui.dialogs.PropertyPage; - - - -/** - * Preference page to associate set of style sheets to Papyrus project. - *

- * The preference is stored in a file with EMF format. The target is file .settings/stylesheets.xmi - *

- * - * @author gpascual - */ -public class StyleSheetsPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { - - /** Text for preference page label. */ - private static final String PREFERENCE_PAGE_LABEL = Messages.getString("StyleSheetsPropertyPage.preference.page.label"); //$NON-NLS-1$ - - /** Text for preference page title. */ - private static final String PREFERENCE_PAGE_TITLE = Messages.getString("StyleSheetsPropertyPage.preference.page.title"); //$NON-NLS-1$ - - /** 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. - * - */ - public StyleSheetsPropertyPage() { - //This preference is stored with EMF format : .settings/stylesheets.xmi - setPreferenceStore(null); - noDefaultAndApplyButton(); - } - - - /** - * Get Style sheets model file to manage preference. - * - * @return a new style sheets list or the existing one - */ - private EList getProjectStylesheets() { - //Get selected project - Object pageElement = getElement().getAdapter(IProject.class); - - //Initialize preferences data - ResourceSet resourceSet = new ResourceSetImpl(); - EList styleSheetsList = 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"); //$NON-NLS-1$ - - // 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.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true), true); - styleSheetsList = resource.getContents(); - - - } else { - - //Create default preference file - resource = resourceSet.createResource(URI.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true)); - styleSheetsList = resource.getContents(); - } - } - } - - return styleSheetsList; - } - - /** - * - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - * - * @param parent - * @return - */ - @Override - protected Control createContents(Composite parent) { - - // Create the container composite - Composite container = new Composite(parent, SWT.NONE); - GridLayout containerLayout = new GridLayout(2, false); - container.setLayout(containerLayout); - - // Initialize data and providers for page - initializeDataPage(); - initializeProviders(); - - // Create different components - createLabelPage(container); - createStyleSheetsPageViewer(container); - createStyleSheetsPageButtons(container); - - //Update state buttons - updateButton(); - - return container; - } - - - - - /** - * Create label for page. - * - * @param parent - * Parent composite where compound will added - */ - private void createLabelPage(Composite parent) { - Label labelPage = new Label(parent, SWT.NONE); - - GridData layoutData = new GridData(SWT.FILL); - layoutData.horizontalSpan = 2; - labelPage.setLayoutData(layoutData); - - labelPage.setText(PREFERENCE_PAGE_LABEL); - - } - - - /** - * Initialize preference page. - */ - private void initializeDataPage() { - - EList stylesheetsModel = getProjectStylesheets(); - modelStyleSheets = (ModelStyleSheets)StylesheetsPackage.eINSTANCE.getEFactoryInstance().create(StylesheetsPackage.Literals.MODEL_STYLE_SHEETS); - modelStyleSheets.getStylesheets(); - List mirrorList = new ArrayList(); - 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 result = new LinkedList(); - 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()); //$NON-NLS-1$ //$NON-NLS-2$ - 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, PREFERENCE_PAGE_TITLE); - 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()); //$NON-NLS-1$ //$NON-NLS-2$ - 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()); - - - } - - /** - * - * @see org.eclipse.jface.preference.PreferencePage#performOk() - * - * @return - */ - @Override - public boolean performOk() { - boolean performOK = false; - - try { - resource.getContents().addAll(modelStyleSheets.getStylesheets()); - - // Save preference file - resource.save(Collections.EMPTY_MAP); - performOK = true; - } catch (IOException e) { - Activator.log.error(e); - } - - 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 = ""; //$NON-NLS-1$ - - if(element instanceof StyleSheetReference) { - text = ((StyleSheetReference)element).getPath(); - } else if(element instanceof EmbeddedStyleSheet) { - text = ((EmbeddedStyleSheet)element).getLabel(); - } - - return text; - } - - - - } - - - -} -- cgit v1.2.3