From a174352dd68d69367bcb468722a0bd0938802e2a Mon Sep 17 00:00:00 2001 From: Gabriel Pascual Date: Tue, 29 Apr 2014 18:24:08 +0200 Subject: 430079: [CSS] Papyrus shall provide features to define local theme https://bugs.eclipse.org/bugs/show_bug.cgi?id=430079 Patch 3 : - Fix major issue - Fix comment's remarks Patch 2 : - Rebase to pass hudson verification Pathch 1 : - Use workspace relative path for selected css files during CSS theme edition - Fix "restore default" button action in CSS preference page - Harmonisation of all UI for theme icon selection - Add dialog to confirm theme deletion - Refactor to resolve some dependency problems - Creation of widget for XWT theme view - Add embedded style sheets in CSS Workspace engine working - Fix problems of label provider for CSS themes properties view - Add workspace themes preference page - Add definition of theme property view - Fix saving step of an edited theme from workspace - Fix loading of theme icon in label provider - Fix behavior of theme edition dialog fields - Add edition action on style sheets list - Add move up and move down actions in edition dialog - Add actions (add and delete) to dialog - Resolution staying conflicts after last merge - Add edition theme dialog from project explorer - Minor modification of Style sheet metamodel - Modify CSS engine and theme manager to look at workspace theme contributions - Add theme creation by selecting one or more CSS files - Add dialog to define theme from CSS file in workspace - Create one menu for two actions to manage local theme - Manage command ID in handler - Fix containment relationship in model - Add draft of theme creation from a CSS selection - Modification of style sheets model - Add popup menu on CSS file Change-Id: Ie46281e334252bfbed727c18a431677761db2a45 Signed-off-by: Gabriel Pascual --- .../model/Environment.xmi | 27 +- .../model/properties/css.ctx | 194 ++-- .../model/properties/ui/SingleTheme.xwt | 32 + .../plugin.xml | 97 ++ .../creation/ThemePropertyEditorFactory.java | 58 + .../properties/dialog/CSSThemeCreationDialog.java | 559 ++++++++++ .../properties/dialog/CSSThemeEditionDialog.java | 1133 +++++++++++++++++++ .../fieldeditor/IDynamicFieldEditor.java | 41 + .../fieldeditor/InputComboFieldEditor.java | 279 +++++ .../css/properties/handler/CSSFileHandler.java | 135 +++ .../modelelement/CSSThemesModelElement.java | 69 ++ .../modelelement/CSSThemesModelElementFactory.java | 65 ++ .../preferences/ThemePreferencesPage.java | 1134 ++++++++++++++++++++ .../properties/provider/CSSThemeLabelProvider.java | 99 +- .../org.eclipse.papyrus.infra.gmfdiag.css/.project | 5 - .../META-INF/MANIFEST.MF | 7 +- .../plugin.xml | 9 - .../gmfdiag/css/engine/WorkspaceCSSEngine.java | 168 +-- .../gmfdiag/css/helper/WorkspaceThemesHelper.java | 302 ++++++ .../preferences/ThemePreferenceInitializer.java | 59 +- .../css/preferences/ThemePreferencesPage.java | 95 -- .../papyrus/infra/gmfdiag/css/theme/Theme.java | 67 -- .../infra/gmfdiag/css/theme/ThemeManager.java | 758 +++++++++---- .../META-INF/MANIFEST.MF | 40 +- .../Model/StyleSheets.ecore | 48 +- .../Model/StyleSheets.genmodel | 46 +- .../css/stylesheets/StylesheetsFactory.java | 138 +-- .../css/stylesheets/StylesheetsPackage.java | 950 +++++++++------- .../infra/gmfdiag/css/stylesheets/Theme.java | 123 +++ .../gmfdiag/css/stylesheets/WorkspaceThemes.java | 42 + .../stylesheets/impl/StylesheetsFactoryImpl.java | 259 +++-- .../stylesheets/impl/StylesheetsPackageImpl.java | 662 +++++++----- .../gmfdiag/css/stylesheets/impl/ThemeImpl.java | 327 ++++++ .../css/stylesheets/impl/WorkspaceThemesImpl.java | 152 +++ .../util/StylesheetsAdapterFactory.java | 425 ++++---- .../css/stylesheets/util/StylesheetsSwitch.java | 432 ++++---- .../infra/widgets/editors/BrowseFileEditor.java | 408 +++++++ .../model/Environment.xmi | 111 +- .../widgets/BrowseFilePropertyEditor.java | 175 +++ 39 files changed, 7754 insertions(+), 1976 deletions(-) create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleTheme.xwt create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/creation/ThemePropertyEditorFactory.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dialog/CSSThemeCreationDialog.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dialog/CSSThemeEditionDialog.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/IDynamicFieldEditor.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/InputComboFieldEditor.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/handler/CSSFileHandler.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElement.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElementFactory.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/preferences/ThemePreferencesPage.java create mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/WorkspaceThemesHelper.java delete mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java delete mode 100644 plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/Theme.java create mode 100644 plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/Theme.java create mode 100644 plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/WorkspaceThemes.java create mode 100644 plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/ThemeImpl.java create mode 100644 plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/WorkspaceThemesImpl.java create mode 100644 plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BrowseFileEditor.java create mode 100644 plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/widgets/BrowseFilePropertyEditor.java diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/Environment.xmi b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/Environment.xmi index 4f5fe3cf2fa..d610db8ed4e 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/Environment.xmi +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/Environment.xmi @@ -1,19 +1,8 @@ - - - - - - - + + + + + + + + diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx index 6b4fb350795..f8cbcf7a6f6 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx @@ -1,88 +1,106 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleTheme.xwt b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleTheme.xwt new file mode 100644 index 00000000000..ddcb484a7ef --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleTheme.xwt @@ -0,0 +1,32 @@ + + + + + + + + + + All images + PNG Icon + GIF Icon + JPEG Icon + + + + + *.gif;*.png;*.jpeg + *.png + *.gif + *.jpeg + + + + + \ No newline at end of file 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 ca63aef4b60..9875e752e98 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 @@ -13,6 +13,103 @@ environmentModel="model/Environment.xmi"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + filterExtensions = Arrays.asList(new String[]{ "*.gif;*.png;*.jpeg", "*.gif", "*.png", "*.jpeg" }); + + /** List of name associated to valid extensions. */ + private List filterNames = Arrays.asList(new String[]{ "All images", "GIF Icon", "PNG Icon", "JPEG Icon" }); + + /** Text for dialog title. */ + private static final String DIALOG_TITLE = "CSS Theme Definition"; + + /** Text for theme icon field. */ + private static final String ICON_PATH_LABEL = "Icon"; + + /** Text for theme label field. */ + private static final String THEME_NAME_LABEL = "Label"; + + /** Id of browse button. */ + private static final int BROWSE_BUTTON_ID = 13; + + /** Theme to definr with dialog. */ + private Theme theme = null; + + /** Theme label field. */ + private Text themeLabelField = null; + + /** Theme icon path field. */ + private Text iconPathField = null; + + /** Theme style sheets viewer. */ + private TreeViewer styleSheetsViewer = null; + + /** Menu of browse button to select theme icon. */ + private Menu browseMenu = null; + + /** + * Default constructor. + * + * @param parentShell + * shell of parent widget + * @param theme + * theme to edit + */ + public CSSThemeCreationDialog(Shell parentShell, Theme theme) { + super(parentShell); + + // Set theme to edit + this.theme = theme; + initialiseFilterLabels(filterNames, filterExtensions); + } + + /** + * Gets the filter labels. + * + * @param filterNames + * the filter names + * @param filterExtensions + * the filter extensions + */ + private void initialiseFilterLabels(List filterNames, List filterExtensions) { + int size = Math.min(filterNames.size(), filterExtensions.size()); + String[] filters = new String[size]; + for(int i = 0; i < size; i++) { + filters[i] = filterNames.get(i) + " (" + filterExtensions.get(i) + ")"; + } + + this.filterNames = Arrays.asList(filters); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#getInitialSize() + * + * @return + */ + @Override + protected Point getInitialSize() { + return new Point(320, 360); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#isResizable() + * + * @return + */ + @Override + protected boolean isResizable() { + + // Set dialog resizable + return true; + } + + /** + * + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + * + * @param newShell + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + + // Add title and icon to dialog + newShell.setText(DIALOG_TITLE); + newShell.setImage(PapyrusImageUtils.getDefaultIcon()); + } + + + /** + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + * + * @param parent + * @return + */ + @Override + protected Control createDialogArea(Composite parent) { + + // Create main container to dialog + Composite mainComposite = (Composite)super.createDialogArea(parent); + mainComposite.setLayout(new GridLayout(2, false)); + + // Add different parts to dialog + createThemeLabelPart(mainComposite); + createThemeIconPart(mainComposite); + createStyleSheetsTreeComposite(mainComposite); + + // Initialise tree viewer + initialiseTree(); + + return mainComposite; + } + + /** + * Create all components for theme label. + * + * @param parent + * Composite where components will be added + */ + private void createThemeLabelPart(Composite parent) { + + // Label for theme name field + Label themeNameLabel = new Label(parent, SWT.NONE); + themeNameLabel.setText(THEME_NAME_LABEL); + + // Field to edit theme label + themeLabelField = new Text(parent, SWT.BORDER); + GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.horizontalSpan = 2; + themeLabelField.setLayoutData(layoutData); + + // Add behavior to text field + themeLabelField.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + theme.setLabel(themeLabelField.getText()); + } + }); + } + + /** + * Create all components for theme icon. + * + * @param parent + * Composite where components will be added + */ + private void createThemeIconPart(Composite parent) { + + //Label for theme icon field + Label themeIconLabel = new Label(parent, SWT.NONE); + themeIconLabel.setText(ICON_PATH_LABEL); + + // Field to edit icon path for theme + iconPathField = new Text(parent, SWT.BORDER); + iconPathField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // Add behavior to text field + iconPathField.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + theme.setIcon(iconPathField.getText()); + } + }); + + + // Add browse button to help user + Button browseButton = createButton(parent, BROWSE_BUTTON_ID, BROWSE_BUTTON_LABEL, false); + + browseMenu = new Menu(browseButton); + + createMenuItem(browseMenu, FILE_SYSTEM_MENU_LABEL, FILESYSTEM_MENU_ID); + createMenuItem(browseMenu, WORKSPACE_MENU_LABEL, WORKSPACE_MENU_ID); + + } + + /** + * Create menu item. + * + * @param parentMenu + * Menu where it will be added + * @param label + * Label of menu item + * @param menuId + */ + private void createMenuItem(Menu parentMenu, String label, int menuId) { + + MenuItem menuItem = new MenuItem(parentMenu, SWT.NONE); + menuItem.setText(label); + menuItem.setData(new Integer(menuId)); + menuItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + menuSelected(((Integer)e.widget.getData()).intValue()); + } + }); + + + } + + /** + * Action to run when a menu is slected. + * + * @param menuId + * ID of selected menu + */ + private void menuSelected(int menuId) { + switch(menuId) { + case WORKSPACE_MENU_ID: + browseWorkspace(); + break; + case FILESYSTEM_MENU_ID: + browseFileSytem(); + break; + default: + // Nothing to do + break; + } + } + + /** + * Browse file in file system. + */ + private void browseFileSytem() { + File file = getFile(iconPathField.getText()); + + FileDialog dialog = new FileDialog(getShell()); + dialog.setText(ICON_SELECTION_DIALOG_TITLE); + + dialog.setFileName(file.getAbsolutePath()); + dialog.setFilterExtensions(filterExtensions.toArray(new String[filterExtensions.size()])); + dialog.setFilterNames(filterNames.toArray(new String[filterNames.size()])); + + String result = dialog.open(); + if(result == null) { //Cancel + return; + } + setResult(result); + } + + /** + * Browse file in workspace. + */ + private void browseWorkspace() { + LabelProviderService labelProviderService = new LabelProviderServiceImpl(); + try { + labelProviderService.startService(); + } catch (ServiceException ex) { + Activator.log.error(ex); + } + + ILabelProvider labelProvider = labelProviderService.getLabelProvider(); + + IFile currentFile = getIFile(iconPathField.getText()); + + TreeSelectorDialog dialog = new TreeSelectorDialog(getShell()); + dialog.setTitle(ICON_SELECTION_DIALOG_TITLE); + + + WorkspaceContentProvider contentProvider = new WorkspaceContentProvider(); + + + if(!(filterExtensions.isEmpty() || filterNames.isEmpty())) { + //The filters have been defined + contentProvider.setExtensionFilters(new LinkedHashMap()); //Reset the default filters + + //Use our own filters + for(int i = 0; i < Math.min(filterNames.size(), filterExtensions.size()); i++) { + contentProvider.addExtensionFilter(filterExtensions.get(i), filterNames.get(i)); + } + } + + dialog.setContentProvider(contentProvider); + dialog.setLabelProvider(labelProvider); + + + if(currentFile != null && currentFile.exists()) { + dialog.setInitialSelections(new IFile[]{ currentFile }); + } + + int code = dialog.open(); + if(code == Window.OK) { + Object[] result = dialog.getResult(); + if(result.length > 0) { + Object file = result[0]; + if(file instanceof IFile) { + setResult((IFile)file); + } + } + } + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + * + * @param buttonId + */ + @Override + protected void buttonPressed(int buttonId) { + + switch(buttonId) { + case BROWSE_BUTTON_ID: + browseMenu.setVisible(true); + break; + default: + super.buttonPressed(buttonId); + break; + } + + } + + + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(IFile file) { + iconPathField.setText(file.getFullPath().toString()); + } + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(File file) { + iconPathField.setText(file.getAbsolutePath()); + + } + + /** + * Sets the result. + * + * @param path + * the new result + */ + protected void setResult(String path) { + iconPathField.setText(path); + + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the i file + */ + protected IFile getIFile(String path) { + return FileUtil.getIFile(path); + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the file + */ + protected File getFile(String path) { + return FileUtil.getFile(path); + } + + + + /** + * Create composite containing style sheets viewer. + * + * @param parent + * Composite where components will be added + */ + private void createStyleSheetsTreeComposite(Composite parent) { + + styleSheetsViewer = new TreeViewer(parent, SWT.BORDER); + Tree tree = styleSheetsViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + } + + /** + * Initialise display of style sheets tree viewer. + */ + private void initialiseTree() { + styleSheetsViewer.setContentProvider(new EMFContentProvider(theme, StylesheetsPackage.eINSTANCE.getTheme_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 Theme) { + result.addAll(theme.getStylesheets()); + } + return result.toArray(); + } + }; + + } + }); + + styleSheetsViewer.setLabelProvider(new StyleSheetLabelProvider()); + styleSheetsViewer.setInput(theme.getStylesheets()); + } + + + /** + * Label provider for style sheets tree viwer. + * + * @author gpascual + * + */ + private class StyleSheetLabelProvider extends BaseLabelProvider implements ILabelProvider { + + /** + * Default constructor. + * + */ + public StyleSheetLabelProvider() { + super(); + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + * + * @param element + * @return + */ + public Image getImage(Object element) { + return null; + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + * + * @param element + * @return + */ + public String getText(Object element) { + String text = element.toString(); + + if(element instanceof StyleSheetReference) { + text = ((StyleSheetReference)element).getPath(); + } + + return text; + } + + } + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dialog/CSSThemeEditionDialog.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dialog/CSSThemeEditionDialog.java new file mode 100644 index 00000000000..d25c0f16e51 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/dialog/CSSThemeEditionDialog.java @@ -0,0 +1,1133 @@ +/***************************************************************************** + * 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.dialog; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.Assert; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ComboViewer; +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.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.utils.PapyrusImageUtils; +import org.eclipse.papyrus.infra.emf.providers.EMFContentProvider; +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.StyleSheet; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes; +import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; +import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl; +import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog; +import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider; +import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.infra.widgets.util.FileUtil; +import org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * Dialog to edit theme from an initial selection in workspace. + * + * @author gpascual + * + */ +public class CSSThemeEditionDialog extends Dialog { + + /** Title for icon selection dialog. */ + private static final String ICON_SELECTION_DIALOG_TITLE = "Icon selection"; + + /** Label for workspace menu. */ + private static final String WORKSPACE_MENU_LABEL = "Workspace"; + + /** Label for file system menu. */ + private static final String FILESYSTEM_MENU_LABEL = "File System"; + + /** Id of workspace menu. */ + private static final int WORKSPACE_MENU_ID = 23; + + /** Id of of file system menu */ + private static final int FILESYSTEM_MENU_ID = 22; + + /** Id of edit button. */ + private static final int EDIT_BUTTON_ID = 19; + + /** Id of down button. */ + private static final int DOWN_BUTTON_ID = 18; + + /** Id of up button. */ + private static final int UP_BUTTON_ID = 17; + + /** ID of delete button. */ + private static final int DELETE_BUTTON_ID = 15; + + /** ID of add button. */ + private static final int ADD_BUTTON_ID = 14; + + /** ID of browse buton. */ + private static final int BROWSE_BUTTON_ID = 16; + + /** Array of all id's buttons which were added in dialog. */ + private static int[] actionIdList = new int[]{ DOWN_BUTTON_ID, UP_BUTTON_ID, DELETE_BUTTON_ID, ADD_BUTTON_ID, BROWSE_BUTTON_ID, EDIT_BUTTON_ID }; + + /** Title for add action dialog. */ + private static final String ADD_DIALOG_TITLE = "Style sheets selection"; + + /** Icon for edit action 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 delete action button. */ + private static final Image DELETE_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Delete_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Icon for add action button. */ + private static final Image ADD_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Add_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$ + + /** Text for style sheets list label. */ + private static final String STYLE_SHEETS_LABEL = "Style sheets"; + + /** Text for browse button. */ + private static final String BROWSE_BUTTON_LABEL = "Browse..."; + + /** Text for theme icon label. */ + private static final String THEME_ICON_LABEL = "Icon"; + + /** Text for theme name label. */ + private static final String THEME_NAME_LABEL = "Label"; + + /** Text for theme combo label. */ + private static final String THEME_COMBO_LABEL = "Theme"; + + /** Title of dialog. */ + private static final String DIALOG_TITLE = "CSS Theme Edition"; + + /** List of valid extensions for an icon. */ + private List filterExtensions = Arrays.asList(new String[]{ "*.gif;*.png;*.jpeg", "*.gif", "*.png", "*.jpeg" }); + + /** List of name associated to valid extensions. */ + private List filterNames = Arrays.asList(new String[]{ "All images", "GIF Icon", "PNG Icon", "JPEG Icon" }); + + /** Field for theme label. */ + private Text themeLabelField = null; + + /** Field for theme icon path. */ + private Text iconPathfield = null; + + /** Workspace themes from preference file. */ + private WorkspaceThemes workspaceThemes = null; + + /** Initial selection in workspace. */ + private List selectedStyleSheetsList = null; + + /** Viewer for style sheets of current theme. */ + private TreeViewer themeStyleSheetsViewer = null; + + /** Factory to edit contents of dialog. */ + private EcorePropertyEditorFactory editorFactory = new EcorePropertyEditorFactory(StylesheetsPackage.eINSTANCE.getTheme_Stylesheets()); + + /** Current edited theme. */ + private Theme currentTheme = null; + + /** Label provider for different composites. */ + private LabelProvider labelProvider = null; + + /** Menu for browse button. */ + private Menu browseMenu = null; + + + /** + * Default constructor. + * + * @param parentShell + */ + public CSSThemeEditionDialog(Shell parentShell, WorkspaceThemes themes, IStructuredSelection parentSelection) { + super(parentShell); + workspaceThemes = themes; + initialiseFilterLabels(filterNames, filterExtensions); + initialiseWithSelection(parentSelection); + } + + + /** + * Gets the filter labels. + * + * @param filterNames + * the filter names + * @param filterExtensions + * the filter extensions + */ + private void initialiseFilterLabels(List filterNames, List filterExtensions) { + int size = Math.min(filterNames.size(), filterExtensions.size()); + String[] filters = new String[size]; + for(int i = 0; i < size; i++) { + filters[i] = filterNames.get(i) + " (" + filterExtensions.get(i) + ")"; + } + this.filterNames = Arrays.asList(filters); + } + + /** + * Initialise selected style sheets list with selection. + * + * @param selection + * Source to extract style sheets + */ + private void initialiseWithSelection(IStructuredSelection selection) { + Assert.isNotNull(selection); + + // Instantiate an empty list + selectedStyleSheetsList = new ArrayList(); + + // Create iterator and factory for initialisation + Iterator selectionIterator = selection.iterator(); + StylesheetsFactory styleSheetsFactory = StylesheetsFactory.eINSTANCE; + + // Explore selection + while(selectionIterator.hasNext()) { + + // Check only file from selection + Object object = selectionIterator.next(); + if(object instanceof IFile) { + + // Create a style sheet reference and add it to list + StyleSheetReference reference = styleSheetsFactory.createStyleSheetReference(); + reference.setPath(((IFile)object).getFullPath().toString()); + + selectedStyleSheetsList.add(reference); + } + } + + + } + + /** + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + * + * @param newShell + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + + // Set title and icon of dialog + newShell.setText(DIALOG_TITLE); + newShell.setImage(PapyrusImageUtils.getDefaultIcon()); + } + + /** + * Create contents of the dialog. + * + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite)super.createDialogArea(parent); + container.setLayout(new GridLayout(2, false)); + + createEditedThemeComposite(container); + createThemeLabelPart(container); + createThemeIconPart(container); + createTreeActionButtons(container); + createThemeStyleSheetsPart(container); + + refreshDialogContent(null); + + return container; + } + + /** + * Create composite whith that can select theme to edit. + * + * @param parent + * Parent composite where components will be added + */ + private void createEditedThemeComposite(Composite parent) { + + // Label for combo of themes + Label themeLabel = new Label(parent, SWT.NONE); + themeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + themeLabel.setText(THEME_COMBO_LABEL); + + // Create a combo so that user can choice theme to edit + ComboViewer comboViewer = new ComboViewer(parent, SWT.READ_ONLY); + comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + /** + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + * + * @param event + */ + public void selectionChanged(SelectionChangedEvent event) { + + // Refresh content of dialog + refreshDialogContent(event.getSelection()); + + } + }); + + // Add label provider to combo viewer + comboViewer.setLabelProvider(new LabelProvider() { + + /** + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + * + * @param element + * @return + */ + @Override + public String getText(Object element) { + + // Super return as default result + String text = super.getText(element); + + // Display label of theme in combo viewer + if(element instanceof Theme) { + text = ((Theme)element).getLabel(); + } + + + return text; + } + }); + + comboViewer.setContentProvider(new EMFContentProvider(workspaceThemes, StylesheetsPackage.eINSTANCE.getWorkspaceThemes_Themes()) { + + /** + * @see org.eclipse.papyrus.infra.emf.providers.EMFContentProvider#getSemanticProvider(org.eclipse.emf.ecore.EObject, + * org.eclipse.emf.ecore.EStructuralFeature) + * + * @param editedEObject + * @param feature + * @return + */ + @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(); + + // Create list with workspace themes + if(editedEObject instanceof WorkspaceThemes) { + result.addAll(workspaceThemes.getThemes()); + } + + return result.toArray(); + } + }; + + } + }); + + comboViewer.setInput(workspaceThemes.getThemes()); + Combo combo = comboViewer.getCombo(); + combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); + } + + /** + * Create theme label composite. + * + * @param parent + * Parent composite where components will be added + */ + private void createThemeLabelPart(Composite parent) { + + // Create label for label field + Label themeNameLabel = new Label(parent, SWT.NONE); + themeNameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + themeNameLabel.setText(THEME_NAME_LABEL); + + // Add theme label field + themeLabelField = new Text(parent, SWT.BORDER); + GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + themeLabelField.setLayoutData(gd_text); + + themeLabelField.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + currentTheme.setLabel(themeLabelField.getText()); + + } + }); + } + + /** + * Create theme icon part. + * + * @param parent + * Parent composite where components will be added + */ + private void createThemeIconPart(Composite parent) { + Label iconLabel = new Label(parent, SWT.NONE); + iconLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + iconLabel.setText(THEME_ICON_LABEL); + + iconPathfield = new Text(parent, SWT.BORDER); + iconPathfield.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + iconPathfield.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + currentTheme.setIcon(iconPathfield.getText()); + + } + }); + Button browseButton = createButton(parent, BROWSE_BUTTON_ID, BROWSE_BUTTON_LABEL, false); + browseMenu = new Menu(browseButton); + + createMenuItem(browseMenu, FILESYSTEM_MENU_LABEL, FILESYSTEM_MENU_ID); + createMenuItem(browseMenu, WORKSPACE_MENU_LABEL, WORKSPACE_MENU_ID); + } + + /** + * Create menu item. + * + * @param parentMenu + * Menu where it will be added + * @param label + * Label of menu item + * @param menuId + */ + private void createMenuItem(Menu parentMenu, String label, int menuId) { + + MenuItem menuItem = new MenuItem(browseMenu, SWT.NONE); + menuItem.setText(label); + menuItem.setData(new Integer(menuId)); + menuItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + menuSelected(((Integer)e.widget.getData()).intValue()); + } + }); + + + } + + /** + * Action to run when a menu is slected. + * + * @param menuId + * ID of selected menu + */ + private void menuSelected(int menuId) { + switch(menuId) { + case WORKSPACE_MENU_ID: + browseWorkspace(); + break; + case FILESYSTEM_MENU_ID: + browseFileSytem(); + break; + default: + // Nothing to do + break; + } + } + + /** + * Browse file in file system. + */ + private void browseFileSytem() { + File file = getFile(iconPathfield.getText()); + + FileDialog dialog = new FileDialog(getShell()); + dialog.setText(ICON_SELECTION_DIALOG_TITLE); + + dialog.setFileName(file.getAbsolutePath()); + dialog.setFilterExtensions(filterExtensions.toArray(new String[filterExtensions.size()])); + dialog.setFilterNames(filterNames.toArray(new String[filterNames.size()])); + String result = dialog.open(); + if(result == null) { //Cancel + return; + } + setResult(result); + } + + /** + * Browse file in workspace. + */ + private void browseWorkspace() { + LabelProviderService labelProviderService = new LabelProviderServiceImpl(); + try { + labelProviderService.startService(); + } catch (ServiceException ex) { + Activator.log.error(ex); + } + + ILabelProvider labelProvider = labelProviderService.getLabelProvider(); + + IFile currentFile = getIFile(iconPathfield.getText()); + + TreeSelectorDialog dialog = new TreeSelectorDialog(getShell()); + dialog.setTitle(ICON_SELECTION_DIALOG_TITLE); + + + WorkspaceContentProvider contentProvider = new WorkspaceContentProvider(); + + + if(!(filterExtensions.isEmpty() || filterNames.isEmpty())) { + //The filters have been defined + contentProvider.setExtensionFilters(new LinkedHashMap()); //Reset the default filters + + //Use our own filters + for(int i = 0; i < Math.min(filterNames.size(), filterExtensions.size()); i++) { + contentProvider.addExtensionFilter(filterExtensions.get(i), filterNames.get(i)); + } + } + + dialog.setContentProvider(contentProvider); + dialog.setLabelProvider(labelProvider); + + + if(currentFile != null && currentFile.exists()) { + dialog.setInitialSelections(new IFile[]{ currentFile }); + } + + int code = dialog.open(); + if(code == Window.OK) { + Object[] result = dialog.getResult(); + if(result.length > 0) { + Object file = result[0]; + if(file instanceof IFile) { + setResult((IFile)file); + } + } + } + } + + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(IFile file) { + iconPathfield.setText(file.getFullPath().toString()); + } + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(File file) { + iconPathfield.setText(file.getAbsolutePath()); + + } + + /** + * Sets the result. + * + * @param path + * the new result + */ + protected void setResult(String path) { + iconPathfield.setText(path); + + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the i file + */ + protected IFile getIFile(String path) { + return FileUtil.getIFile(path); + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the file + */ + protected File getFile(String path) { + return FileUtil.getFile(path); + } + + + /** + * Create theme style sheets part. + * + * @param parent + * Parent composite where components will be added + */ + private void createThemeStyleSheetsPart(Composite parent) { + + // Create viewer + themeStyleSheetsViewer = new TreeViewer(parent, SWT.BORDER); + + // Set standard collection content provider + themeStyleSheetsViewer.setContentProvider(CollectionContentProvider.instance); + + labelProvider = new LabelProvider() { + + /** + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + * + * @param element + * @return + */ + @Override + public String getText(Object element) { + + // Use ancestor result as default + String text = super.getText(element); + + // Display path of style sheet reference + if(element instanceof StyleSheetReference) { + text = ((StyleSheetReference)element).getPath(); + } else if(element instanceof EmbeddedStyleSheet) { + text = ((EmbeddedStyleSheet)element).getLabel(); + } + + return text; + } + }; + themeStyleSheetsViewer.setLabelProvider(labelProvider); + + // Set layout + Tree tree = themeStyleSheetsViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + + } + + /** + * Create actions associate to tree viewer. + * + * @param parent + * Composite where action buttons will be added + */ + private void createTreeActionButtons(Composite parent) { + Label labelViewer = new Label(parent, SWT.NONE); + labelViewer.setText(STYLE_SHEETS_LABEL); + + Composite buttonsPanel = new Composite(parent, SWT.NONE); + buttonsPanel.setLayout(new GridLayout()); + buttonsPanel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false, 2, 1)); + + createButton(buttonsPanel, ADD_BUTTON_ID, ADD_ICON, false); + createButton(buttonsPanel, DELETE_BUTTON_ID, DELETE_ICON, false); + createButton(buttonsPanel, UP_BUTTON_ID, UP_ICON, false); + createButton(buttonsPanel, DOWN_BUTTON_ID, DOWN_ICON, false); + createButton(buttonsPanel, EDIT_BUTTON_ID, EDIT_ICON, false); + + } + + + /** + * Override method to create a button with an icon and no label. + * + * @see org.eclipse.jface.dialogs.Dialog#createButton(Composite, int, String, boolean) + * + * @param parent + * @param id + * @param icon + * @return + */ + protected Button createButton(Composite parent, int id, Image icon, boolean defaultButton) { + Button button = super.createButton(parent, id, "", defaultButton); + button.setImage(icon); + return button; + } + + /** + * + * Override method to define specific data layout for own dialog's buttons. + * + * @see org.eclipse.jface.dialogs.Dialog#setButtonLayoutData(org.eclipse.swt.widgets.Button) + * + * @param button + */ + @Override + protected void setButtonLayoutData(Button button) { + + // Determine id of button + Object data = button.getData(); + int buttonId = -1; + if(data instanceof Integer) { + buttonId = (Integer)data; + } + + //Filter specific button to set data layout + switch(buttonId) { + case ADD_BUTTON_ID: + case DELETE_BUTTON_ID: + case UP_BUTTON_ID: + case DOWN_BUTTON_ID: + case EDIT_BUTTON_ID: + button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + break; + default: + super.setButtonLayoutData(button); + break; + } + + + } + + /** + * Delete current selection of tree viewer. + */ + private void deleteAction() { + ISelection selection = themeStyleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + if(selectedElement instanceof StyleSheet) { + currentTheme.getStylesheets().remove(selectedElement); + } + + themeStyleSheetsViewer.setInput(currentTheme.getStylesheets()); + refreshTreeviewer(currentTheme); + } + + } + + + /** + * Open a dialog to add a style sheet to current selected theme. + */ + private void addAction() { + + + ReferenceSelector selector = new ReferenceSelector(true); + selector.setContentProvider(new EMFContentProvider(currentTheme, StylesheetsPackage.eINSTANCE.getTheme_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 Theme) { + result.addAll(currentTheme.getStylesheets()); + } + return result.toArray(); + } + }; + } + }); + selector.setLabelProvider(labelProvider); + + // Use common component for add dialog and parameterize it + MultipleValueSelectorDialog vDialog = new MultipleValueSelectorDialog(getShell(), selector, ADD_DIALOG_TITLE); + vDialog.setContextElement(currentTheme); + vDialog.setLabelProvider(labelProvider); + vDialog.setFactory(new EcorePropertyEditorFactory(StylesheetsPackage.Literals.THEME__STYLESHEETS)); + + // Handle dialog result + int result = vDialog.open(); + if(result == Dialog.OK) { + + Object[] resultArray = vDialog.getResult(); + refreshStyleSheets(resultArray); + + } + } + + + /** + * Move up the selected style sheet in list. + */ + private void upAction() { + + // Handle selection to extract selected style sheet + ISelection selection = themeStyleSheetsViewer.getSelection(); + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof StyleSheet) { + + // Get index of selected style sheet in list + EList stylesheetsList = currentTheme.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); + themeStyleSheetsViewer.setInput(stylesheetsList); + } + } + } + } + + /** + * Move down the selected style sheet in list. + */ + private void downAction() { + + // Handle selection to extract selected style sheet + ISelection selection = themeStyleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof StyleSheet) { + + // Get index of selected style sheet in list + EList stylesheetsList = currentTheme.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); + themeStyleSheetsViewer.setInput(stylesheetsList); + } + } + } + } + + + /** + * Edit action on selected style sheet in tree viewer. + */ + private void editAction() { + + ISelection selection = themeStyleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedObject = ((IStructuredSelection)selection).getFirstElement(); + if(selectedObject instanceof StyleSheet) { + // Use editor factory + editorFactory.edit(getContents(), selectedObject); + } + } + + + } + + + /** + * Fill style sheets viewer with selected style sheets. + * + * @param result + * Result from dialog selection + */ + private void refreshStyleSheets(Object[] result) { + + // Complete current theme with dialog result + for(Object object : result) { + + // Check if this is a style sheet + if(object instanceof StyleSheet) + currentTheme.getStylesheets().add((StyleSheet)object); + } + + refreshTreeviewer(currentTheme); + } + + + /** + * Refresh content of tree viewer according to selected theme/ + * + * @param currentTheme + * Current theme + */ + private void refreshTreeviewer(Theme currentTheme) { + + if(currentTheme != null) { + + EList themeStyleSheetsList = currentTheme.getStylesheets(); + + + // For each selected reference, check match with existing reference in theme + for(StyleSheet basereference : selectedStyleSheetsList) { + + // Flag for search + boolean found = false; + int i = 0; + + // Explore theme style s + while(i < themeStyleSheetsList.size() && !found) { + + // Use own comparator to determine if style sheet reference exist + found = StylesheetsComparator.instance.compare(themeStyleSheetsList.get(i), basereference) == 0; + i++; + } + + // Add selected reference only if it don't exist in theme + if(!found) { + themeStyleSheetsList.add(basereference); + } + } + + // Set mirroring list as viewer input + themeStyleSheetsViewer.setInput(themeStyleSheetsList); + } + + updateButtons(currentTheme); + + } + + + /** + * + * Update state of dialog buttons. + * + * @param currentTheme + * Selected theme which determine state of different buttons. + */ + private void updateButtons(Theme currentTheme) { + boolean editionEnable = currentTheme != null; + + for(int buttonId : actionIdList) { + switch(buttonId) { + case ADD_BUTTON_ID: + case BROWSE_BUTTON_ID: + getButton(buttonId).setEnabled(editionEnable); + break; + case DELETE_BUTTON_ID: + case EDIT_BUTTON_ID: + getButton(buttonId).setEnabled(editionEnable && !currentTheme.getStylesheets().isEmpty()); + break; + case UP_BUTTON_ID: + case DOWN_BUTTON_ID: + getButton(buttonId).setEnabled(editionEnable && (currentTheme.getStylesheets().size() > 1)); + default: + break; + } + + } + + } + + /** + * Refresh dialog area according to combo selection. + * + * @param selection + * selection which comes from combo viewer + */ + protected void refreshDialogContent(ISelection selection) { + + // Current selected theme + currentTheme = null; + + // Get selected theme from combo + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof Theme) { + currentTheme = (Theme)selectedElement; + } + } + + + + boolean editionEnable = currentTheme != null; + themeLabelField.setEditable(editionEnable); + iconPathfield.setEditable(editionEnable); + + if(editionEnable) { + + // Refresh text field (label, icon path, ...) + String themeLabel = currentTheme.getLabel(); + if(themeLabel == null) { + themeLabel = ""; + } + themeLabelField.setText(themeLabel); + + + String iconPath = currentTheme.getIcon(); + if(iconPath == null) { + iconPath = ""; + } + iconPathfield.setText(iconPath); + } + + // Tree viewer + refreshTreeviewer(currentTheme); + + } + + + /** + * Create contents of the button bar. + * + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + * + * @param buttonId + */ + @Override + protected void buttonPressed(int buttonId) { + switch(buttonId) { + case ADD_BUTTON_ID: + addAction(); + break; + case DELETE_BUTTON_ID: + deleteAction(); + break; + case BROWSE_BUTTON_ID: + browseMenu.setVisible(true); + break; + case UP_BUTTON_ID: + upAction(); + break; + case DOWN_BUTTON_ID: + downAction(); + break; + case EDIT_BUTTON_ID: + editAction(); + default: + super.buttonPressed(buttonId); + } + } + + + + /** + * Return the initial size of the dialog. + */ + @Override + protected Point getInitialSize() { + return new Point(450, 300); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#isResizable() + * + * @return + */ + @Override + protected boolean isResizable() { + return true; + } + + /** + * @return last selected theme for edition + */ + public Theme getEditedTheme() { + return currentTheme; + } + + /** + * Comparator basic for style sheets. It compare path for reference and label for embedded. + */ + public static class StylesheetsComparator implements Comparator { + + public static final Comparator instance = new StylesheetsComparator(); + + /** + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + * + * @param firstStyleSheet + * @param secondStyleSheet + * @return + */ + public int compare(StyleSheet firstStyleSheet, StyleSheet secondStyleSheet) { + + // Default result for comparison + boolean comparisonResult = false; + String rightOperand = null; + String leftOperand = null; + + if(firstStyleSheet instanceof StyleSheetReference && secondStyleSheet instanceof StyleSheetReference) { + + // Get both compared reference path + rightOperand = ((StyleSheetReference)firstStyleSheet).getPath(); + leftOperand = ((StyleSheetReference)secondStyleSheet).getPath(); + + // Use standard string comparison + comparisonResult = rightOperand.equals(leftOperand); + + } else if(firstStyleSheet instanceof EmbeddedStyleSheet && secondStyleSheet instanceof EmbeddedStyleSheet) { + + // Get both of compared embedded label + rightOperand = ((EmbeddedStyleSheet)firstStyleSheet).getLabel(); + leftOperand = ((EmbeddedStyleSheet)secondStyleSheet).getLabel(); + + // Use standard string comparison + comparisonResult = rightOperand.equals(leftOperand); + } + + // Final comparison value + int comparisonValue = -1; + if(comparisonResult) { + comparisonValue = 0; + } + + return comparisonValue; + } + + + + } + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/IDynamicFieldEditor.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/IDynamicFieldEditor.java new file mode 100644 index 00000000000..6e5def40a0d --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/IDynamicFieldEditor.java @@ -0,0 +1,41 @@ +/***************************************************************************** + * 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.fieldeditor; + + +/** + * Interface for dynamic field editor. Standard field editors don't permit to update its input or set current selection. + * + * @author gpascual + */ +public interface IDynamicFieldEditor { + + + /** + * Set input to field editor. + * + * @param input + * New value of field editor input + */ + void setInput(Object input); + + /** + * Set current selection to field editor. + * + * @param selectedValue + * Value of selected element + * + */ + void setSelection(String selectedValue); + + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/InputComboFieldEditor.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/InputComboFieldEditor.java new file mode 100644 index 00000000000..76d8e9515ac --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/fieldeditor/InputComboFieldEditor.java @@ -0,0 +1,279 @@ +/***************************************************************************** + * 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.fieldeditor; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + + +/** + * Implementation of dynamic combo field editor. Add {@link IDynamicFieldEditor} interface behavior to standard combo field editor. + * + * @see org.eclipse.jface.preference.ComboFieldEditor + * + * @author gpascual + * + */ +public class InputComboFieldEditor extends FieldEditor implements IDynamicFieldEditor { + + /** + * The Combo widget. + */ + private Combo combo = null; + + /** + * The value (not the name) of the currently selected item in the Combo widget. + */ + private String value = null; + + /** + * The names (labels) and underlying values to populate the combo widget. These should be + * arranged as: { {name1, value1}, {name2, value2}, ...} + */ + private String[][] fEntryNamesAndValues = null; + + /** + * Create the combo box field editor. + * + * @param name + * the name of the preference this field editor works on + * @param labelText + * the label text of the field editor + * @param entryNamesAndValues + * the names (labels) and underlying values to populate the combo widget. These should be + * arranged as: { {name1, value1}, {name2, value2}, ...} + * @param parent + * the parent composite + */ + public InputComboFieldEditor(String name, String labelText, String[][] entryNamesAndValues, Composite parent) { + init(name, labelText); + Assert.isTrue(checkArray(entryNamesAndValues)); + fEntryNamesAndValues = entryNamesAndValues; + createControl(parent); + } + + /** + * Checks whether given String[][] is of "type" String[][2]. + * + * @return true if it is ok, and false otherwise + */ + private boolean checkArray(String[][] table) { + if(table == null) { + return false; + } + for(int i = 0; i < table.length; i++) { + String[] array = table[i]; + if(array == null || array.length != 2) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int) + */ + @Override + protected void adjustForNumColumns(int numColumns) { + if(numColumns > 1) { + Control control = getLabelControl(); + int left = numColumns; + if(control != null) { + ((GridData)control.getLayoutData()).horizontalSpan = 1; + left = left - 1; + } + ((GridData)combo.getLayoutData()).horizontalSpan = left; + } else { + Control control = getLabelControl(); + if(control != null) { + ((GridData)control.getLayoutData()).horizontalSpan = 1; + } + ((GridData)combo.getLayoutData()).horizontalSpan = 1; + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt.widgets.Composite, int) + */ + @Override + protected void doFillIntoGrid(Composite parent, int numColumns) { + int comboC = 1; + if(numColumns > 1) { + comboC = numColumns - 1; + } + Control control = getLabelControl(parent); + GridData gd = new GridData(); + gd.horizontalSpan = 1; + control.setLayoutData(gd); + control = getComboBoxControl(parent); + gd = new GridData(); + gd.horizontalSpan = comboC; + gd.horizontalAlignment = GridData.FILL; + control.setLayoutData(gd); + control.setFont(parent.getFont()); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#doLoad() + */ + @Override + protected void doLoad() { + updateComboForValue(getPreferenceStore().getString(getPreferenceName())); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#doLoadDefault() + */ + @Override + protected void doLoadDefault() { + updateComboForValue(getPreferenceStore().getDefaultString(getPreferenceName())); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#doStore() + */ + @Override + protected void doStore() { + if(value == null) { + getPreferenceStore().setToDefault(getPreferenceName()); + return; + } + getPreferenceStore().setValue(getPreferenceName(), value); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.FieldEditor#getNumberOfControls() + */ + @Override + public int getNumberOfControls() { + return 2; + } + + /* + * Lazily create and return the Combo control. + */ + private Combo getComboBoxControl(Composite parent) { + if(combo == null) { + combo = new Combo(parent, SWT.READ_ONLY); + combo.setFont(parent.getFont()); + for(int i = 0; i < fEntryNamesAndValues.length; i++) { + combo.add(fEntryNamesAndValues[i][0], i); + } + + combo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent evt) { + String oldValue = value; + String name = combo.getText(); + value = getValueForName(name); + setPresentsDefaultValue(false); + fireValueChanged(VALUE, oldValue, value); + } + }); + } + return combo; + } + + /* + * Given the name (label) of an entry, return the corresponding value. + */ + private String getValueForName(String name) { + for(int i = 0; i < fEntryNamesAndValues.length; i++) { + String[] entry = fEntryNamesAndValues[i]; + if(name.equals(entry[0])) { + return entry[1]; + } + } + return fEntryNamesAndValues[0][0]; + } + + /* + * Set the name in the combo widget to match the specified value. + */ + private void updateComboForValue(String value) { + this.value = value; + for(int i = 0; i < fEntryNamesAndValues.length; i++) { + if(value.equals(fEntryNamesAndValues[i][1])) { + combo.setText(fEntryNamesAndValues[i][0]); + return; + } + } + if(fEntryNamesAndValues.length > 0) { + value = fEntryNamesAndValues[0][1]; + combo.setText(fEntryNamesAndValues[0][0]); + } + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean, org.eclipse.swt.widgets.Composite) + * + * @param enabled + * @param parent + */ + @Override + public void setEnabled(boolean enabled, Composite parent) { + super.setEnabled(enabled, parent); + getComboBoxControl(parent).setEnabled(enabled); + } + + /** + * @see org.eclipse.papyrus.infra.gmfdiag.css.properties.fieldeditor.IDynamicFieldEditor#setInput(java.lang.Object) + * + * @param input + */ + public void setInput(Object input) { + + if(input.getClass().equals(fEntryNamesAndValues.getClass())) { + fEntryNamesAndValues = (String[][])input; + } + + combo.removeAll(); + for(int i = 0; i < fEntryNamesAndValues.length; i++) { + combo.add(fEntryNamesAndValues[i][0], i); + } + + doLoad(); + + } + + /** + * @see org.eclipse.papyrus.infra.gmfdiag.css.properties.fieldeditor.IDynamicFieldEditor#setSelection(java.lang.String) + * + * @param newValue + */ + public void setSelection(String newValue) { + String oldValue = this.value; + updateComboForValue(newValue); + fireValueChanged(VALUE, oldValue, newValue); + + } +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/handler/CSSFileHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/handler/CSSFileHandler.java new file mode 100644 index 00000000000..482a0806b93 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/handler/CSSFileHandler.java @@ -0,0 +1,135 @@ +/***************************************************************************** + * 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.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.runtime.IPath; +import org.eclipse.emf.common.util.URI; +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.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.gmfdiag.css.helper.WorkspaceThemesHelper; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.dialog.CSSThemeCreationDialog; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.dialog.CSSThemeEditionDialog; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes; +import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + + +/** + * + * Handler to define a CSS style sheet file as local theme. + * + * @author gpascual + * + */ +public class CSSFileHandler extends AbstractHandler implements IHandler { + + /** ID of command to edit existing theme. */ + private static final String THEME_EDIT_COMMAND_ID = "org.eclipse.papyrus.infra.gmfdiag.css.theme.edit"; //$NON-NLS-1$ + + /** ID of command to define theme. */ + private static final String THEME_DEFINE_COMMAND_ID = "org.eclipse.papyrus.infra.gmfdiag.css.theme.define"; //$NON-NLS-1$ + + /** */ + private WorkspaceThemesHelper cssHelper = new WorkspaceThemesHelper(); + + /** + * Default constructor. + * + */ + public CSSFileHandler() { + super(); + } + + /** + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + * + * @param event + * @return + * @throws ExecutionException + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + + Theme theme = null; + int dialogResult = -1; + + + // Get current selection + ISelection selection = HandlerUtil.getCurrentSelection(event); + + // Get selected file from selection + if(selection instanceof IStructuredSelection) { + + // Get executed command ID + String commandID = event.getCommand().getId(); + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + + if(THEME_DEFINE_COMMAND_ID.equals(commandID)) { + + // Get theme initialise with slected elements + theme = cssHelper.defineCSSStyleSheetFilesAsTheme((IStructuredSelection)selection); + // Open a specific dialog to define theme according to selection + Dialog dialog = new CSSThemeCreationDialog(shell, theme); + dialogResult = dialog.open(); + + + } else if(THEME_EDIT_COMMAND_ID.equals(commandID)) { + IPath workspaceThemesFilePath = cssHelper.getThemeWorkspacePreferenceFilePath(); + + WorkspaceThemes workspaceThemes = null; + if(workspaceThemesFilePath.toFile().exists()) { + ResourceSet resourceSet = new ResourceSetImpl(); + Resource resource = resourceSet.getResource(URI.createFileURI(workspaceThemesFilePath.toOSString()), true); + workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(resource.getContents(), StylesheetsPackage.Literals.WORKSPACE_THEMES); + } + + // Open a specific dialog to edit existing theme according to selection + CSSThemeEditionDialog dialog = new CSSThemeEditionDialog(shell, workspaceThemes, (IStructuredSelection)selection); + dialogResult = dialog.open(); + + theme = dialog.getEditedTheme(); + + + + } + + // Save and reload themes list only if user has validated + if(dialogResult == Dialog.OK) { + + if(THEME_DEFINE_COMMAND_ID.equals(commandID)) { + cssHelper.saveNewThemeWorkspacePreference(theme); + } else if(THEME_EDIT_COMMAND_ID.equals(commandID)) { + cssHelper.saveWorkspaceThemesPreferenceResource(theme); + } + + ThemeManager.instance.reloadThemes(); + } + + } + + + return null; + } +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElement.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElement.java new file mode 100644 index 00000000000..6d54d2890d9 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElement.java @@ -0,0 +1,69 @@ +/***************************************************************************** + * 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.modelelement; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.provider.CSSStyleSheetLabelProvider; +import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement; +import org.eclipse.papyrus.views.properties.modelelement.ModelElement; + + +/** + * Theme ModelElement to provide corresponding label provider because EMF model + * is not register in service registry. + * + * @author gpascual + * + */ +public class CSSThemesModelElement extends EMFModelElement implements ModelElement { + + /** UI view path for theme style sheets. */ + private static final String THEME_STYLESHEETS_PATH = "stylesheets"; //$NON-NLS-1$ + + /** + * Default constructor. + * + * @param source + * @param domain + */ + public CSSThemesModelElement(EObject source, EditingDomain domain) { + super(source, domain); + } + + /** + * @see org.eclipse.papyrus.views.properties.modelelement.EMFModelElement#getLabelProvider(java.lang.String) + * + * @param propertyPath + * @return + */ + @Override + public ILabelProvider getLabelProvider(String propertyPath) { + + ILabelProvider labelProvider = null; + + + if(THEME_STYLESHEETS_PATH.equals(propertyPath)) { + labelProvider = new CSSStyleSheetLabelProvider(); + } + + // If label provider was not instantiated, we use this ancestor one + if(labelProvider == null) { + labelProvider = super.getLabelProvider(propertyPath); + } + + return labelProvider; + } + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElementFactory.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElementFactory.java new file mode 100644 index 00000000000..ade28c59815 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSThemesModelElementFactory.java @@ -0,0 +1,65 @@ +/***************************************************************************** + * 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.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.views.properties.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; + + +/** + * Themes ModelElement factory to provide label provider because + * CSS EMF model is not in Service registry. + * + * @author gpascual + * + */ +public class CSSThemesModelElementFactory implements ModelElementFactory { + + + /** + * Default constructor. + * + */ + public CSSThemesModelElementFactory() { + super(); + } + + /** + * @see org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory#createFromSource(java.lang.Object, + * org.eclipse.papyrus.views.properties.contexts.DataContextElement) + * + * @param sourceElement + * @param context + * @return + */ + 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); + + // Create CSS themes ModelElement + return new CSSThemesModelElement(source, domain); + } + + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/preferences/ThemePreferencesPage.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/preferences/ThemePreferencesPage.java new file mode 100644 index 00000000000..bb1dcb561e5 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/preferences/ThemePreferencesPage.java @@ -0,0 +1,1134 @@ +/***************************************************************************** + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.css.properties.preferences; + +import java.io.File; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.emf.providers.EMFContentProvider; +import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper; +import org.eclipse.papyrus.infra.gmfdiag.css.Activator; +import org.eclipse.papyrus.infra.gmfdiag.css.engine.WorkspaceCSSEngine; +import org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferences; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.creation.ThemePropertyEditorFactory; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.fieldeditor.IDynamicFieldEditor; +import org.eclipse.papyrus.infra.gmfdiag.css.properties.fieldeditor.InputComboFieldEditor; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet; +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.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager; +import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; +import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl; +import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog; +import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider; +import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.infra.widgets.util.FileUtil; +import org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +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.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * A Preference page for selecting the Workspace CSS Theme + * + * @author Camille Letavernier + */ +public class ThemePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + /** Title for icon selection dialog. */ + private static final String ICON_SELECTION_DIALOG_TITLE = "Icon selection"; + + /** Label for workspace menu. */ + private static final String WORKSPACE_MENU_LABEL = "Workspace"; + + /** Label for file system menu. */ + private static final String FILE_SYSTEM_MENU_LABEL = "File System"; + + /** Id of workspace menu item. */ + private static final int WORKSPACE_MENU_ID = 12; + + /** Id of file system menu item. */ + private static final int FILESYSTEM_MENU_ID = 25; + + /** Label of theme field editor. */ + private static final String CURRENT_THEME_FIELD_LABEL = "Current theme:"; + + /** Title of preference page. */ + private static final String PAGE_TITLE = "CSS Theme"; + + /** Id of delete theme button. */ + private static final int DELETE_THEME_BUTTON_ID = 46; + + /** Id of new button. */ + private static final int NEW_THEME_BUTTON_ID = 45; + + /** Id of edit button. */ + private static final int EDIT_BUTTON_ID = 19; + + /** Id of down button. */ + private static final int DOWN_BUTTON_ID = 18; + + /** Id of up button. */ + private static final int UP_BUTTON_ID = 17; + + /** ID of delete button. */ + private static final int DELETE_BUTTON_ID = 15; + + /** ID of add button. */ + private static final int ADD_BUTTON_ID = 14; + + /** ID of browse buton. */ + private static final int BROWSE_BUTTON_ID = 16; + + /** Title for add action dialog. */ + private static final String ADD_DIALOG_TITLE = "Style sheets selection"; + + 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 delete action button. */ + private static final Image DELETE_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Delete_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** Icon for add action button. */ + private static final Image ADD_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Add_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$ + + /** Text for style sheets list label. */ + private static final String STYLE_SHEETS_LABEL = "Style sheets"; + + /** Text for browse button. */ + private static final String BROWSE_BUTTON_LABEL = "Browse..."; + + /** Text for theme icon label. */ + private static final String THEME_ICON_LABEL = "Icon"; + + /** Text for theme name label. */ + private static final String THEME_NAME_LABEL = "Label"; + + /** List of valid extensions for an icon. */ + private List filterExtensions = Arrays.asList(new String[]{ "*.gif;*.png;*.jpeg", "*.gif", "*.png", "*.jpeg" }); + + /** List of name associated to valid extensions. */ + private List filterNames = Arrays.asList(new String[]{ "All images", "GIF Icon", "PNG Icon", "JPEG Icon" }); + + /** Flag to define if refresh must be done. */ + public boolean needsRefresh = false; + + /** Main composite of preference page. */ + private Composite mainContainer = null; + + /** Field for label of theme. */ + private Text themeLabelField = null; + + /** Current selected theme. */ + protected Theme currentTheme = null; + + /** Field for icon path of theme. */ + private Text iconPathfield = null; + + /** Viewer for style sheets of current theme. */ + private TreeViewer themeStyleSheetsViewer = null; + + /** Label provider for treeviewer. */ + private LabelProvider labelProvider = null; + + /** Dynamic combo editor for select theme preference. */ + private IDynamicFieldEditor themesCombo = null; + + /** Array of all id's buttons which were added in dialog. */ + private Map buttonsMap = new HashMap(); + + /** Editor factory for theme. */ + private EcorePropertyEditorFactory editorFactory = new ThemePropertyEditorFactory(StylesheetsPackage.Literals.WORKSPACE_THEMES__THEMES); + + /** Menu of icon browse button. */ + private Menu browseMenu = null; + + + /** + * + * Default constructor. + * + */ + public ThemePreferencesPage() { + super(PAGE_TITLE, org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"), FieldEditorPreferencePage.GRID); + initialiseFilterLabels(filterNames, filterExtensions); + } + + /** + * Gets the filter labels. + * + * @param filterNames + * the filter names + * @param filterExtensions + * the filter extensions + */ + private void initialiseFilterLabels(List filterNames, List filterExtensions) { + int size = Math.min(filterNames.size(), filterExtensions.size()); + String[] filters = new String[size]; + + for(int i = 0; i < size; i++) { + filters[i] = filterNames.get(i) + " (" + filterExtensions.get(i) + ")"; + } + + this.filterNames = Arrays.asList(filters); + } + + /** + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + * + * @param workbench + */ + public void init(IWorkbench workbench) { + + //Used default preference store to save current theme + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + + // Set description for page + setDescription("Papyrus Theme preferences"); + } + + + /** + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createContents(org.eclipse.swt.widgets.Composite) + * + * @param parent + * @return + */ + @Override + protected Control createContents(Composite parent) { + + // Create principal layout + mainContainer = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.marginHeight = 0; + layout.marginWidth = 0; + mainContainer.setLayout(layout); + mainContainer.setFont(parent.getFont()); + + // Populate preference page + createPreferenceThemePart(mainContainer); + createThemeLabelPart(mainContainer); + createThemeIconPart(mainContainer); + createTreeActionButtons(mainContainer); + createThemeStyleSheetsPart(mainContainer); + + // Initialize step + initialize(); + checkState(); + + + return mainContainer; + } + + /** + * Create part of page to select, add and remove theme. + * + * @param parent + * Parent composite where components will be added + */ + private void createPreferenceThemePart(Composite parent) { + + // Add theme field editor + createFieldEditors(); + Composite buttonsPanel = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginLeft = 0; + layout.marginRight = 0; + buttonsPanel.setLayout(layout); + buttonsPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + + // Add buttons to delete and add theme + createButton(buttonsPanel, NEW_THEME_BUTTON_ID, ADD_ICON, null); + createButton(buttonsPanel, DELETE_THEME_BUTTON_ID, DELETE_ICON, null); + + } + + /** + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() + * + */ + @Override + protected void createFieldEditors() { + //Get all themes define in application instance + String[][] themes = getFieldThemes(); + + themesCombo = new InputComboFieldEditor(ThemePreferences.CURRENT_THEME, CURRENT_THEME_FIELD_LABEL, themes, mainContainer); + + + addField((FieldEditor)themesCombo); + + + } + + /** + * Create theme label composite. + * + * @param parent + * Parent composite where components will be added + */ + private void createThemeLabelPart(Composite parent) { + + // Create label for label field + Label themeNameLabel = new Label(parent, SWT.NONE); + themeNameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + themeNameLabel.setText(THEME_NAME_LABEL); + + // Add theme label field + themeLabelField = new Text(parent, SWT.BORDER); + GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + themeLabelField.setLayoutData(gd_text); + + themeLabelField.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + currentTheme.setLabel(themeLabelField.getText()); + } + + + }); + } + + + /** + * Create theme icon part. + * + * @param parent + * Parent composite where components will be added + */ + private void createThemeIconPart(Composite parent) { + Label iconLabel = new Label(parent, SWT.NONE); + iconLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + iconLabel.setText(THEME_ICON_LABEL); + + iconPathfield = new Text(parent, SWT.BORDER); + iconPathfield.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + iconPathfield.addModifyListener(new ModifyListener() { + + + public void modifyText(ModifyEvent e) { + currentTheme.setIcon(iconPathfield.getText()); + + } + }); + + // Create browse button and its menu + Button browseButton = createButton(parent, BROWSE_BUTTON_ID, null, BROWSE_BUTTON_LABEL); + browseMenu = new Menu(browseButton); + createMenuItem(browseMenu, FILE_SYSTEM_MENU_LABEL, FILESYSTEM_MENU_ID); + createMenuItem(browseMenu, WORKSPACE_MENU_LABEL, WORKSPACE_MENU_ID); + } + + /** + * Create menu item. + * + * @param parentMenu + * Menu where it will be added + * @param label + * Label of menu item + * @param menuId + */ + private void createMenuItem(Menu parentMenu, String label, int menuId) { + + MenuItem menuItem = new MenuItem(parentMenu, SWT.NONE); + menuItem.setText(label); + menuItem.setData(new Integer(menuId)); + menuItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + menuSelected(((Integer)e.widget.getData()).intValue()); + } + }); + + + } + + /** + * Action to run when a menu is slected. + * + * @param menuId + * ID of selected menu + */ + private void menuSelected(int menuId) { + switch(menuId) { + case WORKSPACE_MENU_ID: + browseWorkspace(); + break; + case FILESYSTEM_MENU_ID: + browseFileSytem(); + break; + default: + // Nothing to do + break; + } + } + + /** + * Browse file in file system. + */ + private void browseFileSytem() { + File file = getFile(iconPathfield.getText()); + + FileDialog dialog = new FileDialog(getShell()); + dialog.setText(ICON_SELECTION_DIALOG_TITLE); + + dialog.setFileName(file.getAbsolutePath()); + dialog.setFilterExtensions(filterExtensions.toArray(new String[filterExtensions.size()])); + dialog.setFilterNames(filterNames.toArray(new String[filterNames.size()])); + String result = dialog.open(); + if(result == null) { //Cancel + return; + } + setResult(result); + } + + /** + * Browse file in workspace. + */ + private void browseWorkspace() { + LabelProviderService labelProviderService = new LabelProviderServiceImpl(); + try { + labelProviderService.startService(); + } catch (ServiceException ex) { + Activator.log.error(ex); + } + + ILabelProvider labelProvider = labelProviderService.getLabelProvider(); + + IFile currentFile = getIFile(iconPathfield.getText()); + + TreeSelectorDialog dialog = new TreeSelectorDialog(getShell()); + dialog.setTitle(ICON_SELECTION_DIALOG_TITLE); + + + WorkspaceContentProvider contentProvider = new WorkspaceContentProvider(); + + + if(!(filterExtensions.isEmpty() || filterNames.isEmpty())) { + //The filters have been defined + contentProvider.setExtensionFilters(new LinkedHashMap()); //Reset the default filters + + //Use our own filters + for(int i = 0; i < Math.min(filterNames.size(), filterExtensions.size()); i++) { + contentProvider.addExtensionFilter(filterExtensions.get(i), filterNames.get(i)); + } + } + + dialog.setContentProvider(contentProvider); + dialog.setLabelProvider(labelProvider); + + + if(currentFile != null && currentFile.exists()) { + dialog.setInitialSelections(new IFile[]{ currentFile }); + } + + int code = dialog.open(); + if(code == Window.OK) { + Object[] result = dialog.getResult(); + if(result.length > 0) { + Object file = result[0]; + if(file instanceof IFile) { + setResult((IFile)file); + } + } + } + } + + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(IFile file) { + iconPathfield.setText(file.getFullPath().toString()); + } + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(File file) { + iconPathfield.setText(file.getAbsolutePath()); + + } + + /** + * Sets the result. + * + * @param path + * the new result + */ + protected void setResult(String path) { + iconPathfield.setText(path); + + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the i file + */ + protected IFile getIFile(String path) { + return FileUtil.getIFile(path); + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the file + */ + protected File getFile(String path) { + return FileUtil.getFile(path); + } + + /** + * Create theme style sheets part. + * + * @param parent + * Parent composite where components will be added + */ + private void createThemeStyleSheetsPart(Composite parent) { + + // Create viewer + themeStyleSheetsViewer = new TreeViewer(parent, SWT.BORDER); + + // Set standard collection content provider + themeStyleSheetsViewer.setContentProvider(CollectionContentProvider.instance); + + labelProvider = new LabelProvider() { + + /** + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + * + * @param element + * @return + */ + @Override + public String getText(Object element) { + + // Use ancestor result as default + String text = super.getText(element); + + // Display path of style sheet reference + if(element instanceof StyleSheetReference) { + text = ((StyleSheetReference)element).getPath(); + } else if(element instanceof EmbeddedStyleSheet) { + text = ((EmbeddedStyleSheet)element).getLabel(); + } + + return text; + } + }; + themeStyleSheetsViewer.setLabelProvider(labelProvider); + + // Set layout + Tree tree = themeStyleSheetsViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + + } + + + /** + * Create actions associate to tree viewer. + * + * @param parent + * Composite where action buttons will be added + */ + private void createTreeActionButtons(Composite parent) { + Label labelViewer = new Label(parent, SWT.NONE); + labelViewer.setText(STYLE_SHEETS_LABEL); + + Composite buttonsPanel = new Composite(parent, SWT.NONE); + buttonsPanel.setLayout(new GridLayout()); + buttonsPanel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false, 2, 1)); + + createButton(buttonsPanel, ADD_BUTTON_ID, ADD_ICON, null); + createButton(buttonsPanel, DELETE_BUTTON_ID, DELETE_ICON, null); + createButton(buttonsPanel, UP_BUTTON_ID, UP_ICON, null); + createButton(buttonsPanel, DOWN_BUTTON_ID, DOWN_ICON, null); + createButton(buttonsPanel, EDIT_BUTTON_ID, EDIT_ICON, null); + + } + + /** + * Override method to create a button with an icon and no label. + * + * @see org.eclipse.jface.dialogs.Dialog#createButton(Composite, int, String, boolean) + * + * @param parent + * @param id + * @param icon + * @return + */ + protected Button createButton(Composite parent, int id, Image icon, String label) { + ((GridLayout)parent.getLayout()).numColumns++; + Button button = new Button(parent, SWT.PUSH); + button.setFont(JFaceResources.getDialogFont()); + button.setData(new Integer(id)); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(((Integer)event.widget.getData()).intValue()); + } + }); + + if(label != null) { + button.setText(label); + } + if(icon != null) { + button.setImage(icon); + } + buttonsMap.put(new Integer(id), button); + setButtonLayoutData(button); + return button; + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + * + * @param buttonId + */ + protected void buttonPressed(int buttonId) { + switch(buttonId) { + case ADD_BUTTON_ID: + addAction(); + break; + case DELETE_BUTTON_ID: + deleteAction(); + break; + case BROWSE_BUTTON_ID: + browseMenu.setVisible(true); + break; + case UP_BUTTON_ID: + upAction(); + break; + case DOWN_BUTTON_ID: + downAction(); + break; + case EDIT_BUTTON_ID: + editAction(); + break; + case NEW_THEME_BUTTON_ID: + addThemeAction(); + break; + case DELETE_THEME_BUTTON_ID: + deleteThemeAction(); + break; + default: + //Nothing to do + } + } + + + /** + * Delete current selection of tree viewer. + */ + private void deleteAction() { + ISelection selection = themeStyleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + if(selectedElement instanceof StyleSheet) { + currentTheme.getStylesheets().remove(selectedElement); + } + + themeStyleSheetsViewer.setInput(currentTheme.getStylesheets()); + refreshTreeviewer(currentTheme); + } + + } + + + /** + * Open a dialog to add a style sheet to current selected theme. + */ + private void addAction() { + + + ReferenceSelector selector = new ReferenceSelector(true); + selector.setContentProvider(new EMFContentProvider(currentTheme, StylesheetsPackage.eINSTANCE.getTheme_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 Theme) { + result.addAll(currentTheme.getStylesheets()); + } + return result.toArray(); + } + }; + } + }); + selector.setLabelProvider(labelProvider); + + // Use common component for add dialog and parameterize it + MultipleValueSelectorDialog vDialog = new MultipleValueSelectorDialog(getShell(), selector, ADD_DIALOG_TITLE); + vDialog.setContextElement(currentTheme); + vDialog.setLabelProvider(labelProvider); + vDialog.setFactory(new EcorePropertyEditorFactory(StylesheetsPackage.Literals.THEME__STYLESHEETS)); + + // Handle dialog result + int result = vDialog.open(); + if(result == Dialog.OK) { + + Object[] resultArray = vDialog.getResult(); + refreshStyleSheets(resultArray); + + } + + } + + + /** + * Fill style sheets viewer with selected style sheets. + * + * @param result + * Result from dialog selection + */ + private void refreshStyleSheets(Object[] result) { + + // Complete current theme with dialog result + for(Object object : result) { + + // Check if this is a style sheet + if(object instanceof StyleSheet) + currentTheme.getStylesheets().add((StyleSheet)object); + } + + needsRefresh = true; + + refreshTreeviewer(currentTheme); + } + + /** + * Refresh content of tree viewer according to selected theme/ + * + * @param currentTheme + * Current theme + */ + private void refreshTreeviewer(Theme currentTheme) { + + + boolean isEditatble = ThemeManager.instance.isEditable(currentTheme.getId()); + + EList themeStyleSheetsList = currentTheme.getStylesheets(); + + + // Set mirroring list as viewer input + themeStyleSheetsViewer.getTree().setEnabled(isEditatble); + themeStyleSheetsViewer.setInput(themeStyleSheetsList); + + + updateButtons(currentTheme); + + } + + + /** + * Move up the selected style sheet in list. + */ + private void upAction() { + + // Handle selection to extract selected style sheet + ISelection selection = themeStyleSheetsViewer.getSelection(); + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof StyleSheet) { + + // Get index of selected style sheet in list + EList stylesheetsList = currentTheme.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); + themeStyleSheetsViewer.setInput(stylesheetsList); + } + + needsRefresh = true; + } + } + } + + /** + * Move down the selected style sheet in list. + */ + private void downAction() { + + // Handle selection to extract selected style sheet + ISelection selection = themeStyleSheetsViewer.getSelection(); + + if(selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection)selection).getFirstElement(); + + if(selectedElement instanceof StyleSheet) { + + // Get index of selected style sheet in list + EList stylesheetsList = currentTheme.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); + themeStyleSheetsViewer.setInput(stylesheetsList); + } + + needsRefresh = true; + } + } + } + + + /** + * Edit action on selected style sheet in tree viewer. + */ + private void editAction() { + + ISelection selection = themeStyleSheetsViewer.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); + needsRefresh = true; + } + } + + + } + + /** + * Create a theme. + */ + private void addThemeAction() { + + ThemeManager themeManager = ThemeManager.instance; + Object createdObject = editorFactory.createObject(buttonsMap.get(NEW_THEME_BUTTON_ID), themeManager.getWorkspaceThemesPreferences()); + + if(createdObject instanceof Theme) { + + themeManager.addTemporaryTheme((Theme)createdObject); + currentTheme = (Theme)createdObject; + + themesCombo.setInput(getFieldThemes()); + themesCombo.setSelection(((Theme)createdObject).getId()); + + } + } + + /** + * Delete selected theme. + */ + private void deleteThemeAction() { + boolean confirm = MessageDialog.openConfirm(getShell(), "Delete CSS theme", "WARNING! Deletion will be difinitive.\nDo you really want to delete this theme ?"); + if(confirm) { + ThemeManager themeManager = ThemeManager.instance; + themeManager.delete(currentTheme); + String[][] fieldThemes = getFieldThemes(); + themesCombo.setInput(fieldThemes); + currentTheme = themeManager.getTheme(fieldThemes[0][1]); + themesCombo.setSelection(currentTheme.getId()); + } + + } + + /** + * + * Update state of dialog buttons. + * + * @param currentTheme + * Selected theme which determine state of different buttons. + */ + private void updateButtons(Theme currentTheme) { + boolean editionEnable = ThemeManager.instance.isEditable(currentTheme.getId()); + + for(int buttonId : buttonsMap.keySet()) { + switch(buttonId) { + case ADD_BUTTON_ID: + case BROWSE_BUTTON_ID: + buttonsMap.get(buttonId).setEnabled(editionEnable); + break; + case DELETE_BUTTON_ID: + case EDIT_BUTTON_ID: + buttonsMap.get(buttonId).setEnabled(editionEnable && !currentTheme.getStylesheets().isEmpty()); + break; + case UP_BUTTON_ID: + case DOWN_BUTTON_ID: + buttonsMap.get(buttonId).setEnabled(editionEnable && (currentTheme.getStylesheets().size() > 1)); + case DELETE_THEME_BUTTON_ID: + buttonsMap.get(buttonId).setEnabled(ThemeManager.instance.isEditable(currentTheme.getId())); + default: + break; + } + + } + } + + + /** + * @see org.eclipse.jface.dialogs.DialogPage#setButtonLayoutData(org.eclipse.swt.widgets.Button) + * + * @param button + * @return + */ + @Override + protected GridData setButtonLayoutData(Button button) { + GridData layoutData = null; + + // Determine id of button + Object data = button.getData(); + int buttonId = -1; + if(data instanceof Integer) { + buttonId = (Integer)data; + } + + //Filter specific button to set data layout + switch(buttonId) { + case ADD_BUTTON_ID: + case DELETE_BUTTON_ID: + case UP_BUTTON_ID: + case DOWN_BUTTON_ID: + case EDIT_BUTTON_ID: + case DELETE_THEME_BUTTON_ID: + case NEW_THEME_BUTTON_ID: + layoutData = new GridData(SWT.FILL, SWT.FILL, false, false); + button.setLayoutData(layoutData); + break; + default: + layoutData = super.setButtonLayoutData(button); + break; + } + + return layoutData; + } + + /** + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + * + * @param event + */ + + @Override + public void propertyChange(PropertyChangeEvent event) { + super.propertyChange(event); + if(ThemePreferences.CURRENT_THEME.equals(event.getProperty())) { + needsRefresh = true; + } + if(FieldEditor.VALUE.equals(event.getProperty())) { + FieldEditor fieldEditor = (FieldEditor)event.getSource(); + if(ThemePreferences.CURRENT_THEME.equals(fieldEditor.getPreferenceName())) { + + Object newValue = event.getNewValue(); + ThemeManager themeManager = ThemeManager.instance; + + currentTheme = themeManager.getTheme(String.valueOf(newValue)); + refreshPreferencePage(); + + } + } + } + + /** + * Refresh dialog area according to combo selection. + * + * @param selection + * selection which comes from combo viewer + */ + protected void refreshPreferencePage() { + + // Refresh text field (label, icon path, ...) + String themeLabel = currentTheme.getLabel(); + boolean editableTheme = ThemeManager.instance.isEditable(currentTheme.getId()); + needsRefresh = true; + + if(themeLabel == null) { + themeLabel = ""; + } + themeLabelField.setEnabled(editableTheme); + themeLabelField.setText(themeLabel); + + + String iconPath = currentTheme.getIcon(); + if(iconPath == null) { + iconPath = ""; + } + iconPathfield.setEnabled(editableTheme); + iconPathfield.setText(iconPath); + + + // Tree viewer + refreshTreeviewer(currentTheme); + + } + + /** + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#initialize() + * + */ + @Override + protected void initialize() { + String prefrenceValue = getPreferenceStore().getString(ThemePreferences.CURRENT_THEME); + currentTheme = ThemeManager.instance.getTheme(prefrenceValue); + refreshPreferencePage(); + super.initialize(); + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#performApply() + * + */ + @Override + protected void performApply() { + super.performApply(); + themesCombo.setInput(getFieldThemes()); + refreshPreferencePage(); + + } + + /** + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk() + * + * @return + */ + @Override + public boolean performOk() { + boolean result = super.performOk(); + if(needsRefresh) { + WorkspaceCSSEngine.instance.reset(); + DiagramHelper.setNeedsRefresh(); + DiagramHelper.refreshDiagrams(); + } + + + ThemeManager themeManager = ThemeManager.instance; + themeManager.persist(); + return result; + } + + /** + * + * @see org.eclipse.jface.preference.PreferencePage#performCancel() + * + * @return + */ + @Override + public boolean performCancel() { + ThemeManager.instance.reloadThemes(); + ThemeManager.instance.clearTemporaryThemes(); + ThemeManager.instance.clearDeletedThemes(); + + return super.performCancel(); + } + + @Override + protected void performDefaults() { + super.performDefaults(); + + currentTheme = ThemeManager.instance.getTheme(getPreferenceStore().getDefaultString(ThemePreferences.CURRENT_THEME)); + refreshPreferencePage(); + } + + + /** + * @return Formatted themes list for combo field editor + */ + protected String[][] getFieldThemes() { + + // Use a manager to get all theme in application + ThemeManager themeManager = ThemeManager.instance; + themeManager.refreshThemes(); + List themes = themeManager.getThemes(); + + // Build theme list for combo editor + String[][] result = new String[themes.size()][2]; + int i = 0; + for(Theme theme : themes) { + result[i][0] = theme.getLabel(); + result[i][1] = theme.getId(); + i++; + } + + return result; + } + + + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSThemeLabelProvider.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSThemeLabelProvider.java index 288dba9c4be..72ff34250b6 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSThemeLabelProvider.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSThemeLabelProvider.java @@ -1,48 +1,51 @@ -/***************************************************************************** - * 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.properties.provider; - -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.papyrus.infra.gmfdiag.css.theme.Theme; -import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager; -import org.eclipse.swt.graphics.Image; - - -public class CSSThemeLabelProvider extends LabelProvider { - - @Override - public String getText(Object value) { - Theme theme = getTheme(value); - if(theme != null) { - return theme.getLabel(); - } - return super.getText(value); - } - - @Override - public Image getImage(Object value) { - Theme theme = getTheme(value); - if(theme != null) { - return theme.getIcon(); - } - return super.getImage(value); - } - - protected Theme getTheme(Object value) { - if(value instanceof String) { - String themeId = (String)value; - Theme theme = ThemeManager.instance.getTheme(themeId); - return theme; - } - return null; - } -} +/***************************************************************************** + * 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 + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.css.properties.provider; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager; +import org.eclipse.swt.graphics.Image; + + +public class CSSThemeLabelProvider extends LabelProvider { + + @Override + public String getText(Object value) { + Theme theme = getTheme(value); + if(theme != null) { + return theme.getLabel(); + } + return super.getText(value); + } + + @Override + public Image getImage(Object value) { + Theme theme = getTheme(value); + if(theme != null) { + Image icon = ThemeManager.instance.getThemeIcon(theme); + return icon; + } + return super.getImage(value); + } + + protected Theme getTheme(Object value) { + if(value instanceof String) { + String themeId = (String)value; + Theme theme = ThemeManager.instance.getTheme(themeId); + return theme; + } + return null; + } +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/.project b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/.project index 43b7b615238..b4c4ad7ab90 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/.project +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/.project @@ -20,11 +20,6 @@ - - org.eclipse.xtext.ui.shared.xtextBuilder - - - org.eclipse.pde.PluginNature 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 4790d3e81cf..ccfc4d7b985 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 @@ -37,7 +37,9 @@ Require-Bundle: org.eclipse.ui, 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" + org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0", + org.eclipse.papyrus.views.properties;bundle-version="1.0.0", + org.eclipse.papyrus.views.properties.model;bundle-version="1.0.0" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 1.0.0.qualifier @@ -45,7 +47,6 @@ 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-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/plugin.xml b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml index 50f07fcf9be..15c49271c41 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 @@ -17,15 +17,6 @@ styleProvider="org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSAppearanceProvider"> - - - - + * FIXME User could select several CSS files to create a theme + *

+ * + * @param file + */ + public Theme defineCSSStyleSheetFilesAsTheme(IStructuredSelection selection) { + List selectedCSSFilesList = new ArrayList(); + + // Extract file from selection + Iterator selectionIterator = selection.iterator(); + + while(selectionIterator.hasNext()) { + Object next = selectionIterator.next(); + if(next instanceof IFile) { + selectedCSSFilesList.add((IFile)next); + } + } + + // Create a theme from selected CSS file + Theme theme = createThemeFromSelection(selectedCSSFilesList); + theme.setId(EcoreUtil.generateUUID()); + + return theme; + + } + + /** + * Method to persist deleted and edited theme in workspace preference file. + * + * @param editedThemesArray + * Array of edited themes to persist + * @param deletedThemesArray + * Array of deleted theme to persist + */ + public void saveWorkspaceThemesPreferenceResource(Theme[] editedThemesArray, Theme[] deletedThemesArray) { + + // Get current resource of workspace theme preferences + Resource currentThemefile = findThemeFile(); + WorkspaceThemes workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(currentThemefile.getContents(), StylesheetsPackage.Literals.WORKSPACE_THEMES); + + // Handle edited themes + for(Theme editedTheme : editedThemesArray) { + boolean updateResult = updateWorkspaceTheme(editedTheme, workspaceThemes); + + // If update haven't done, theme must be added + if(!updateResult) { + workspaceThemes.getThemes().add(editedTheme); + } + } + + // Handle deleted themes + for(Theme deletedTheme : deletedThemesArray) { + removeWorkspaceTheme(deletedTheme, workspaceThemes); + } + + // Save edited preference file + saveResource(currentThemefile); + + } + + /** + * Method to delete a theme in workspace theme. + * + * @param deletedTheme + * Theme to delete + * @param workspaceThemes + * Current workspace themes + */ + private void removeWorkspaceTheme(Theme deletedTheme, WorkspaceThemes workspaceThemes) { + // Search resource value of edited theme + Iterator currentThemesIterator = workspaceThemes.getThemes().iterator(); + Theme themeId = null; + boolean found = false; + + while(currentThemesIterator.hasNext() && !found) { + themeId = currentThemesIterator.next(); + found = themeId.getId().equals(deletedTheme.getId()); + } + + if(found) { + // Replace in resource the current value with the edited one and save resource + EcoreUtil.remove(workspaceThemes, StylesheetsPackage.eINSTANCE.getWorkspaceThemes_Themes(), themeId); + } + + + + } + + /** + * Replace in current workspace themes resource theme with the edited value. + * + * @param editedTheme + * New theme value + */ + public void saveWorkspaceThemesPreferenceResource(Theme editedTheme) { + // Get current resource of workspace theme preferences + Resource currentThemefile = findThemeFile(); + WorkspaceThemes workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(currentThemefile.getContents(), StylesheetsPackage.Literals.WORKSPACE_THEMES); + + updateWorkspaceTheme(editedTheme, workspaceThemes); + + saveResource(currentThemefile); + } + + /** + * + * Update in current workspace themes resource the theme with the edited one. + * + * @param editedTheme + * Theme with new value + * @param workspaceThemes + * workspace themes + */ + private boolean updateWorkspaceTheme(Theme editedTheme, WorkspaceThemes workspaceThemes) { + // Search resource value of edited theme + Iterator currentThemesIterator = workspaceThemes.getThemes().iterator(); + Theme themeId = null; + boolean found = false; + + while(currentThemesIterator.hasNext() && !found) { + themeId = currentThemesIterator.next(); + found = themeId.getId().equals(editedTheme.getId()); + } + + if(found) { + // Replace in resource the current value with the edited one and save resource + EcoreUtil.replace(workspaceThemes, StylesheetsPackage.eINSTANCE.getWorkspaceThemes_Themes(), themeId, editedTheme); + } + + return found; + } + + /** + * Save style sheets EMF Resource. + * + * @param styleSheetsResource + * + */ + private void saveResource(Resource styleSheetsResource) { + // Save theme preference file + if(styleSheetsResource != null) { + try { + Map options = new HashMap(); + options.put(XMIResource.XMI_ID, Boolean.TRUE); + styleSheetsResource.save(options); + } catch (IOException e) { + Activator.log.error(e); + } + } + } + + + /** + * Save theme in workspace preferences. + * + * @param theme + * Theme to save + */ + public void saveNewThemeWorkspacePreference(Theme theme) { + Resource themeFile = theme.eResource(); + + if(themeFile == null) { + themeFile = findThemeFile(); + } + + // Get workspace themes + WorkspaceThemes workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(themeFile.getContents(), StylesheetsPackage.eINSTANCE.getWorkspaceThemes()); + + // Create a workspace themes root + if(workspaceThemes == null) { + workspaceThemes = StylesheetsFactory.eINSTANCE.createWorkspaceThemes(); + themeFile.getContents().add(workspaceThemes); + } + + // Add created theme + workspaceThemes.getThemes().add(theme); + + saveResource(themeFile); + + } + + /** + * Created a style sheets theme from project selection. + * + * @param selectedCSSFilesList + * @return + */ + private Theme createThemeFromSelection(List selectedCSSFilesList) { + + // Factory to create necessary elements + StylesheetsFactory styleSheetsFactory = StylesheetsFactory.eINSTANCE; + + // Create new theme + Theme newTheme = styleSheetsFactory.createTheme(); + + for(IFile cssFile : selectedCSSFilesList) { + + //Style sheets to add in theme + StyleSheetReference styleSheetsReference = styleSheetsFactory.createStyleSheetReference(); + styleSheetsReference.setPath(cssFile.getFullPath().toString()); + newTheme.getStylesheets().add(styleSheetsReference); + } + return newTheme; + } + + /** + * Look for theme workspace preferences file. + * + * @return Created resource if it don't exist, otherwise loaded + */ + private Resource findThemeFile() { + + IPath themeFilePath = getThemeWorkspacePreferenceFilePath(); + + // Create associated URI + URI resolvedURI = CommonPlugin.resolve(URI.createFileURI(themeFilePath.toOSString())); + + // Create EMF resource + ResourceSet resourceSet = new ResourceSetImpl(); + Resource resource = null; + + if(themeFilePath.toFile().exists()) { + resource = resourceSet.getResource(resolvedURI, true); + } else { + resource = resourceSet.createResource(resolvedURI); + } + + return resource; + } + + /** + * Build path to access preference file. + * + * @return Path to theme.xmi file in workspace preference directory + */ + public IPath getThemeWorkspacePreferenceFilePath() { + // Get workspace path + IPath pluginStatePath = Activator.getDefault().getStateLocation(); + + // Build preference file path + IPath themeFilePath = pluginStatePath.append("theme.xmi"); + return themeFilePath; + } +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferenceInitializer.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferenceInitializer.java index 5e4956b2956..45e320fa97c 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferenceInitializer.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferenceInitializer.java @@ -1,25 +1,34 @@ -/***************************************************************************** - * 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.preferences; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; - -//Unused -public class ThemePreferenceInitializer extends AbstractPreferenceInitializer { - - @Override - public void initializeDefaultPreferences() { - // IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - // store.setDefault(ThemePreferencesPage.CURRENT_THEME, null); - } - -} +/***************************************************************************** + * 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 + * Gabriel Pascual (ALL4TEC) - Initial API and Implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.css.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.infra.gmfdiag.css.Activator; + + +/** + * Theme preference initializer. + * + * @author gpascual + * + */ +public class ThemePreferenceInitializer extends AbstractPreferenceInitializer { + + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + store.setDefault(ThemePreferences.CURRENT_THEME, "org.eclipse.papyrus.css.papyrus_theme"); + } + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java deleted file mode 100644 index 0d1f24dd949..00000000000 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java +++ /dev/null @@ -1,95 +0,0 @@ -/***************************************************************************** - * 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.preferences; - -import java.util.List; - -import org.eclipse.jface.preference.ComboFieldEditor; -import org.eclipse.jface.preference.FieldEditor; -import org.eclipse.jface.preference.FieldEditorPreferencePage; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper; -import org.eclipse.papyrus.infra.gmfdiag.css.Activator; -import org.eclipse.papyrus.infra.gmfdiag.css.engine.WorkspaceCSSEngine; -import org.eclipse.papyrus.infra.gmfdiag.css.theme.Theme; -import org.eclipse.papyrus.infra.gmfdiag.css.theme.ThemeManager; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; - -/** - * A Preference page for selecting the Workspace CSS Theme - * - * @author Camille Letavernier - */ -public class ThemePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { - - public boolean needsRefresh = false; - - /** - * - * Constructor. - * - */ - public ThemePreferencesPage() { - super("CSS Theme", org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"), FLAT); - } - - public void init(IWorkbench workbench) { - setPreferenceStore(Activator.getDefault().getPreferenceStore()); - setDescription("Papyrus Theme preferences"); - } - - @Override - protected void createFieldEditors() { - String[][] themes = getFieldThemes(); - ComboFieldEditor editor = new ComboFieldEditor(ThemePreferences.CURRENT_THEME, "Current theme:", themes, getFieldEditorParent()); - addField(editor); - } - - @Override - public void propertyChange(PropertyChangeEvent event) { - super.propertyChange(event); - if(ThemePreferences.CURRENT_THEME.equals(event.getProperty())) { - needsRefresh = true; - } - if(FieldEditor.VALUE.equals(event.getProperty())) { - if(ThemePreferences.CURRENT_THEME.equals(((FieldEditor)event.getSource()).getPreferenceName())) { - needsRefresh = true; - } - } - } - - @Override - public boolean performOk() { - boolean result = super.performOk(); - if(needsRefresh) { - WorkspaceCSSEngine.instance.reset(); - DiagramHelper.setNeedsRefresh(); - DiagramHelper.refreshDiagrams(); - } - return result; - } - - protected String[][] getFieldThemes() { - List themes = ThemeManager.instance.getThemes(); - - String[][] result = new String[themes.size()][2]; - int i = 0; - for(Theme theme : themes) { - result[i][0] = theme.getLabel(); - result[i][1] = theme.getId(); - i++; - } - return result; - } - -} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/Theme.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/Theme.java deleted file mode 100644 index 91e2172dc61..00000000000 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/Theme.java +++ /dev/null @@ -1,67 +0,0 @@ -/***************************************************************************** - * 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.theme; - -import java.net.URL; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.swt.graphics.Image; - -/** - * A CSS Theme descriptor - * - * @author Camille Letavernier - */ -public class Theme { - - private String label; - - private Image icon; - - private final String id; - - private final List styleSheets; - - public Theme(String id) { - this.id = id; - this.styleSheets = new LinkedList(); - } - - public String getLabel() { - return label == null || "".equals(label) ? id : label; - } - - public void setLabel(String label) { - this.label = label; - } - - public Image getIcon() { - return icon; - } - - public void setIcon(Image icon) { - this.icon = icon; - } - - public String getId() { - return id; - } - - public void addStyleSheet(URL url) { - styleSheets.add(url); - } - - public List getStyleSheets() { - return styleSheets; - } -} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java index d7ca686c397..a01d7fdf426 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java @@ -1,220 +1,538 @@ -/***************************************************************************** - * 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.theme; - -import java.io.IOException; -import java.net.URL; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.preference.IPersistentPreferenceStore; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.papyrus.infra.gmfdiag.css.Activator; -import org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferences; -import org.eclipse.swt.graphics.Image; - -/** - * A Singleton to manage CSS Themes. Reads Themes from an extension point, - * and provides an access to them. - * - * @author Camille Letavernier - * - */ -public class ThemeManager { - - public static String EXTENSION_ID = Activator.PLUGIN_ID + ".theme"; - - public static ThemeManager instance = new ThemeManager(); - - private Map allThemes; - - /** - * Returns all the Themes, sorted alphabetically - * - * @return - */ - public List getThemes() { - List sortedThemes = new LinkedList(getAllThemes().values()); - Collections.sort(sortedThemes, ThemeComparator.instance); - return sortedThemes; - } - - /** - * Returns the list of the workspace stylesheet's URLs. - * - * @return - */ - public List getWorkspaceStyleSheets() { - Theme current = findCurrentTheme(); - if(current == null) { - return Collections.emptyList(); - } - return current.getStyleSheets(); - } - - /** - * Returns the theme associated to the given id, or null if it doesn't - * exist - * - * @param themeId - * @return - */ - public Theme getTheme(String themeId) { - return getAllThemes().get(themeId); - } - - private Map getAllThemes() { - if(allThemes == null) { - allThemes = new LinkedHashMap(); //Keep the themes ordered, to avoid nondeterministic behavior - allThemes.put(EmptyTheme.instance.getId(), EmptyTheme.instance); - IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID); - - loadThemeDefinitions(config); - loadThemeContributions(config); - } - - return allThemes; - } - - private void loadThemeDefinitions(IConfigurationElement[] config) { - for(IConfigurationElement themeConfig : config) { - if(!themeConfig.getName().equals("themeDefinition")) { - continue; - } - - final String themeId = themeConfig.getAttribute("id"); - if(themeId == null) { - Activator.log.warn("Cannot define a CSS Theme with an empty id (Contributed by " + themeConfig.getContributor() + ")"); - continue; - } - Theme theme = new Theme(themeId); - - String themeLabel = themeConfig.getAttribute("label"); - theme.setLabel(themeLabel); - - String themeIcon = themeConfig.getAttribute("icon"); - if(themeIcon != null) { - //FIXME: Use the Papyrus Image service when it is available - Image icon = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(themeConfig.getContributor().getName(), themeIcon); - if(icon != null) { - theme.setIcon(icon); - } - } - - allThemes.put(themeId, theme); - } - } - - private void loadThemeContributions(IConfigurationElement[] config) { - for(IConfigurationElement themeConfig : config) { - if(!themeConfig.getName().equals("themeContribution")) { - continue; - } - - final String themeId = themeConfig.getAttribute("id"); - if(themeId == null || !allThemes.containsKey(themeId)) { - Activator.log.warn("Cannot contribute to an undefined theme: " + themeId); - continue; - } - - Theme theme = allThemes.get(themeId); - - IConfigurationElement[] stylesheets = themeConfig.getChildren("stylesheet"); - for(IConfigurationElement stylesheetConfig : stylesheets) { - String path = stylesheetConfig.getAttribute("stylesheetPath"); - try { - URL url = new URL("platform:/plugin/" + themeConfig.getContributor().getName() + "/" + path); - theme.addStyleSheet(url); - } catch (IOException ex) { - Activator.log.error(ex); - } - } - } - } - - private Theme findCurrentTheme() { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - - if(store.contains(ThemePreferences.CURRENT_THEME)) { - String themeId = store.getString(ThemePreferences.CURRENT_THEME); - Theme theme = getAllThemes().containsKey(themeId) ? getAllThemes().get(themeId) : EmptyTheme.instance; - return theme; - } - - //The theme has not been defined: return the first one, and store it - List sortedThemes = new ArrayList(getAllThemes().values()); - if(sortedThemes.size() < 2) { - return EmptyTheme.instance; - } - - //Index 0 is EmptyTheme ; we return the first non-empty theme - Theme theme = sortedThemes.get(1); - store.setValue(ThemePreferences.CURRENT_THEME, theme.getId()); - try { - ((IPersistentPreferenceStore)store).save(); - } catch (IOException e) { - Activator.log.error(e); - } - return theme; - } - - public static class EmptyTheme extends Theme { - - public static Theme instance = new EmptyTheme(); - - private EmptyTheme() { - super("none"); //$NON-NLS-1$ - setLabel("No theme"); - Image icon = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("icons/Delete_12x12.gif"); - setIcon(icon); - } - } - - /** - * Sorts the Themes alphabetically (Based on their label). The Empty theme - * is always the first element. - * - * @author Camille Letavernier - */ - private static class ThemeComparator implements Comparator { - - private ThemeComparator() { - } - - @Override - public int compare(Theme o1, Theme o2) { - if(o1 == EmptyTheme.instance) { - return -1; - } - if(o2 == EmptyTheme.instance) { - return 1; - } - - return Collator.getInstance().compare(o1.getLabel(), o2.getLabel()); - } - - public static Comparator instance = new ThemeComparator(); - - } - - private ThemeManager() { - - } -} +/***************************************************************************** + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.css.theme; + +import java.io.IOException; +import java.net.URL; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.CommonPlugin; +import org.eclipse.emf.common.util.URI; +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.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.preference.IPersistentPreferenceStore; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.infra.gmfdiag.css.Activator; +import org.eclipse.papyrus.infra.gmfdiag.css.helper.WorkspaceThemesHelper; +import org.eclipse.papyrus.infra.gmfdiag.css.preferences.ThemePreferences; +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.StylesheetsFactory; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.PlatformUI; + +/** + * A Singleton to manage CSS Themes. Reads Themes from an extension point + * and provides an access to them. + * + * @author Camille Letavernier + * + */ +public class ThemeManager { + + /** Extension point ID. */ + public static String EXTENSION_ID = Activator.PLUGIN_ID + ".theme"; + + /** Unique instance of manager. */ + public static ThemeManager instance = new ThemeManager(); + + /** All found themes in application. */ + private Map allThemes = null; + + /** Unsaved themes. */ + private List temporaryThemesList = new ArrayList(); + + /** Themes to delete. */ + private List deletedThemesList = new ArrayList(); + + /** Workspace themes helper. */ + private WorkspaceThemesHelper workspaceThemesHelper = new WorkspaceThemesHelper(); + + /** + * Default constructor. + */ + private ThemeManager() { + //Singleton + } + + /** + * Returns all the Themes, sorted alphabetically + * + * @return + */ + public List getThemes() { + List sortedThemes = new LinkedList(getAllThemes().values()); + Collections.sort(sortedThemes, ThemeComparator.instance); + + return sortedThemes; + } + + /** + * Returns the list of the workspace stylesheet's URLs. + * + * @return + */ + public List getWorkspaceStyleSheets() { + Theme current = findCurrentTheme(); + if(current == null) { + return Collections.emptyList(); + } + return current.getStylesheets(); + } + + /** + * Returns the theme associated to the given id, or null if it doesn't + * exist + * + * @param themeId + * @return + */ + public Theme getTheme(String themeId) { + return getAllThemes().get(themeId); + } + + /** + * Permit to reload known themes list. + */ + public void reloadThemes() { + allThemes = null; + } + + /** + * Refresh known themes list by merging states of themes. + */ + public void refreshThemes() { + + // Handle added themes + for(Theme addedTheme : temporaryThemesList) { + + String key = addedTheme.getId(); + if(!allThemes.containsKey(key)) { + allThemes.put(key, addedTheme); + } + } + + // Handle deleted themes + for(Theme deletedTheme : deletedThemesList) { + String key = deletedTheme.getId(); + if(allThemes.containsKey(key)) { + allThemes.remove(key); + } + } + + } + + + /** + * Clean temporary list of themes. + */ + public void clearTemporaryThemes() { + temporaryThemesList.clear(); + } + + /** + * Clean deleted theme list. + */ + public void clearDeletedThemes() { + deletedThemesList.clear(); + } + + /** + * Add a temporary theme. + * + * @param temporaryTheme + * Theme to add in workspace themes preference + * + */ + public void addTemporaryTheme(Theme temporaryTheme) { + temporaryThemesList.add(temporaryTheme); + } + + /** + * Delete theme from preferences. + * + * @param theme + * Theme to delete + */ + public void delete(Theme theme) { + + // If theme is temporary don't maintain in associated list + if(temporaryThemesList.contains(theme)) { + temporaryThemesList.remove(theme); + } else { + // Else store in a list to be able to cancel + deletedThemesList.add(theme); + } + } + + /** + * Get icon from a theme. Icon can register with plugin URI or file URI. + * + * @param theme + * Theme which can have an icon + * @return Loaded image, otherwise null + */ + public Image getThemeIcon(Theme theme) { + Image icon = null; + + + String iconPath = theme.getIcon(); + if(iconPath != null) { + + // First : looking for theme in contribution + IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID); + icon = handleThemeDefinition(theme, config); + + // Second : Try to load image from its path + if(icon == null) { + + // Test path to icon + IPath path = new Path(iconPath); + if(path.toFile().exists()) { + icon = new Image(PlatformUI.getWorkbench().getDisplay(), iconPath); + } + + } + } + + return icon; + } + + /** + * Return only workspace themes preference. + * + * @return Workspace themes preference (instance of {@link WorkspaceThemes}) if it exist, otherwise null + */ + public WorkspaceThemes getWorkspaceThemesPreferences() { + WorkspaceThemes workspaceThemes = null; + + + // Get path of preference file + IPath path = workspaceThemesHelper.getThemeWorkspacePreferenceFilePath(); + + // If file exist, themes can load + if(path.toFile().exists()) { + // Resolve URI + URI fileURI = CommonPlugin.resolve(URI.createFileURI(path.toOSString())); + + // Create associated resource + ResourceSet resourceSet = new ResourceSetImpl(); + + Resource resource = resourceSet.getResource(fileURI, true); + + + // Get workspace theme + workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(resource.getContents(), StylesheetsPackage.eINSTANCE.getWorkspaceThemes()); + } + + return workspaceThemes; + + } + + /** + * Know if theme is editable. Only themes of workspace or temporary can be edited. + * + * @param id + * Id of theme to check + * @return true if theme can be edited, otherwise false + */ + public boolean isEditable(String id) { + boolean isEditable = false; + + WorkspaceThemes workspacePreference = getWorkspaceThemesPreferences(); + if(workspacePreference != null) { + + // Check if theme existing in temporary + isEditable = temporaryThemesList.contains(allThemes.get(id)); + + //Check if theme comes from workspace preferences + Iterator themesIterator = workspacePreference.getThemes().iterator(); + while(themesIterator.hasNext() && !isEditable) { + isEditable = id.equals(themesIterator.next().getId()); + } + + + } + + return isEditable; + } + + /** + * Persist state of the manager. + */ + public void persist() { + Theme[] editableThemes = getEditableThemes(); + workspaceThemesHelper.saveWorkspaceThemesPreferenceResource(editableThemes, deletedThemesList.toArray(new Theme[deletedThemesList.size()])); + + // Reset manager + allThemes = null; + deletedThemesList.clear(); + temporaryThemesList.clear(); + } + + /** + * @return + */ + private Theme[] getEditableThemes() { + List editableThemeList = new ArrayList(); + + for(Theme theme : allThemes.values()) { + if(isEditable(theme.getId())) { + editableThemeList.add(theme); + } + } + return editableThemeList.toArray(new Theme[editableThemeList.size()]); + } + + /** + * Look for corresponding theme in theme definition contribution and load its image. + * + * @param theme + * Theme to find in all contribution + * @param config + * Configuration of all theme contribution + * @return Loaded image if theme is came from contribution, otherwise null + */ + private Image handleThemeDefinition(Theme theme, IConfigurationElement[] config) { + Image icon = null; + + for(IConfigurationElement themeContribution : config) { + + // Verify that contribution is a theme definition + if(!themeContribution.getName().equals("themeDefinition")) { + continue; + } + + // Get label and Id of definition to compare to parameter + String themeId = themeContribution.getAttribute("id"); + String themeLabel = themeContribution.getAttribute("label"); + + if(themeId != null && themeId.equals(theme.getId()) && themeLabel != null && themeLabel.equals(theme.getLabel())) { + //FIXME: Use the Papyrus Image service when it is available + icon = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(themeContribution.getContributor().getName(), theme.getIcon()); + } + } + + return icon; + } + + private Map getAllThemes() { + if(allThemes == null) { + allThemes = new LinkedHashMap(); //Keep the themes ordered, to avoid nondeterministic behavior + allThemes.put(EmptyTheme.instance.getId(), EmptyTheme.instance); + IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID); + + loadThemeDefinitions(config); + loadThemeContributions(config); + loadThemePreferenceWorkspace(); + loadTemporaryThemes(); + + // Remove deleted themes + for(Theme theme : deletedThemesList) { + String themeId = theme.getId(); + if(allThemes.containsKey(themeId)) { + allThemes.remove(themeId); + } + } + } + + return allThemes; + } + + /** + * Load theme definitions. + * + * @param config + * configuration of all contribution definition + */ + private void loadThemeDefinitions(IConfigurationElement[] config) { + + // For all theme definitions + for(IConfigurationElement themeConfig : config) { + + if(!themeConfig.getName().equals("themeDefinition")) { + continue; + } + + final String themeId = themeConfig.getAttribute("id"); + if(themeId == null) { + Activator.log.warn("Cannot define a CSS Theme with an empty id (Contributed by " + themeConfig.getContributor() + ")"); + continue; + } + + //Create theme + Theme theme = StylesheetsFactory.eINSTANCE.createTheme(); + theme.setId(themeId); + + String themeLabel = themeConfig.getAttribute("label"); + theme.setLabel(themeLabel); + + String themeIcon = themeConfig.getAttribute("icon"); + if(themeIcon != null) { + + theme.setIcon(themeIcon); + + } + + allThemes.put(themeId, theme); + } + } + + /** + * Load theme contributions. + * + * @param config + * configuration of all contribution definition + */ + private void loadThemeContributions(IConfigurationElement[] config) { + for(IConfigurationElement themeConfig : config) { + + // Verify that + if(!themeConfig.getName().equals("themeContribution")) { + continue; + } + + final String themeId = themeConfig.getAttribute("id"); + if(themeId == null || !allThemes.containsKey(themeId)) { + Activator.log.warn("Cannot contribute to an undefined theme: " + themeId); + continue; + } + + Theme theme = allThemes.get(themeId); + + IConfigurationElement[] stylesheets = themeConfig.getChildren("stylesheet"); + for(IConfigurationElement stylesheetConfig : stylesheets) { + String path = stylesheetConfig.getAttribute("stylesheetPath"); + try { + URL url = new URL("platform:/plugin/" + themeConfig.getContributor().getName() + "/" + path); + StyleSheetReference styleSheet = StylesheetsFactory.eINSTANCE.createStyleSheetReference(); + styleSheet.setPath(url.toString()); + theme.getStylesheets().add(styleSheet); + } catch (IOException ex) { + Activator.log.error(ex); + } + } + } + } + + /** + * Load themes of workspace preference. + */ + private void loadThemePreferenceWorkspace() { + + WorkspaceThemes workspaceThemes = getWorkspaceThemesPreferences(); + + // If file exist, themes can load + if(workspaceThemes != null) { + + + // Add each themme to current list + for(Theme theme : workspaceThemes.getThemes()) { + allThemes.put(theme.getId(), theme); + } + + } + } + + /** + * Add temporary themes in current themes list. + */ + private void loadTemporaryThemes() { + for(Theme theme : temporaryThemesList) { + allThemes.put(theme.getId(), theme); + } + + } + + private Theme findCurrentTheme() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + if(store.contains(ThemePreferences.CURRENT_THEME)) { + String themeId = store.getString(ThemePreferences.CURRENT_THEME); + Theme theme = getAllThemes().containsKey(themeId) ? getAllThemes().get(themeId) : EmptyTheme.instance; + return theme; + } + + //The theme has not been defined: return the first one, and store it + List sortedThemes = new ArrayList(getAllThemes().values()); + if(sortedThemes.size() < 2) { + return EmptyTheme.instance; + } + + //Index 0 is EmptyTheme ; we return the first non-empty theme + Theme theme = sortedThemes.get(1); + store.setValue(ThemePreferences.CURRENT_THEME, theme.getId()); + try { + ((IPersistentPreferenceStore)store).save(); + } catch (IOException e) { + Activator.log.error(e); + } + return theme; + } + + public static class EmptyTheme extends ThemeImpl { + + public static Theme instance = new EmptyTheme(); + + private EmptyTheme() { + setId("none"); + setLabel("No theme"); + setIcon("icons/Delete_12x12.gif"); + } + } + + /** + * Sorts the Themes alphabetically (Based on their label). The Empty theme + * is always the first element. + * + * @author Camille Letavernier + */ + private static class ThemeComparator implements Comparator { + + private ThemeComparator() { + } + + @Override + public int compare(Theme o1, Theme o2) { + if(o1 == EmptyTheme.instance) { + return -1; + } + if(o2 == EmptyTheme.instance) { + return 1; + } + + return Collator.getInstance().compare(o1.getLabel(), o2.getLabel()); + } + + public static Comparator instance = new ThemeComparator(); + + } +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/META-INF/MANIFEST.MF index aa425ef0d4d..e180f21db4e 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/META-INF/MANIFEST.MF @@ -1,21 +1,19 @@ -Manifest-Version: 1.0 -Require-Bundle: org.eclipse.core.runtime, - org.eclipse.emf.ecore;visibility:=reexport, - org.eclipse.ui, - org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0", - org.eclipse.uml2.uml;bundle-version="4.0.0" -Export-Package: org.eclipse.papyrus.infra.gmfdiag.css.model, - org.eclipse.papyrus.infra.gmfdiag.css.stylesheets, - org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl, - org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.util -Bundle-Vendor: %providerName -Bundle-ActivationPolicy: lazy -Bundle-ClassPath: . -Bundle-Version: 1.0.0.qualifier -Bundle-Localization: plugin -Bundle-Name: %pluginName -Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.css.model;singl - eton:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.5 - +Manifest-Version: 1.0 +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.emf.ecore;visibility:=reexport, + org.eclipse.ui, + org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0", + org.eclipse.uml2.uml;bundle-version="4.0.0" +Export-Package: org.eclipse.papyrus.infra.gmfdiag.css.model, + org.eclipse.papyrus.infra.gmfdiag.css.stylesheets, + org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl, + org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.util +Bundle-Vendor: %providerName +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: . +Bundle-Version: 1.0.0.qualifier +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.css.model;singleton:=true +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.ecore b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.ecore index 933548c12b1..fe1bb5006d3 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.ecore +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.ecore @@ -1,18 +1,30 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.genmodel b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.genmodel index 720a70cd78a..aac7ed7278c 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.genmodel +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/Model/StyleSheets.genmodel @@ -1,23 +1,23 @@ - - - StyleSheets.ecore - - - - - - - - - - - - - - + + + StyleSheets.ecore + + + + + + + + + + + + + + diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsFactory.java index 27b6b2da365..d11cbef6314 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsFactory.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsFactory.java @@ -1,60 +1,78 @@ -/** - */ -package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets; - -import org.eclipse.emf.ecore.EFactory; - -/** - * - * The Factory for the model. - * It provides a create method for each non-abstract class of the model. - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage - * @generated - */ -public interface StylesheetsFactory extends EFactory { - /** - * The singleton instance of the factory. - * - * - * @generated - */ - StylesheetsFactory eINSTANCE = org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsFactoryImpl.init(); - - /** - * Returns a new object of class 'Model Style Sheets'. - * - * - * @return a new object of class 'Model Style Sheets'. - * @generated - */ - ModelStyleSheets createModelStyleSheets(); - - /** - * Returns a new object of class 'Style Sheet Reference'. - * - * - * @return a new object of class 'Style Sheet Reference'. - * @generated - */ - StyleSheetReference createStyleSheetReference(); - - /** - * Returns a new object of class 'Embedded Style Sheet'. - * - * - * @return a new object of class 'Embedded Style Sheet'. - * @generated - */ - EmbeddedStyleSheet createEmbeddedStyleSheet(); - - /** - * Returns the package supported by this factory. - * - * - * @return the package supported by this factory. - * @generated - */ - StylesheetsPackage getStylesheetsPackage(); - -} //StylesheetsFactory +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets; + +import org.eclipse.emf.ecore.EFactory; + +/** + * + * The Factory for the model. + * It provides a create method for each non-abstract class of the model. + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage + * @generated + */ +public interface StylesheetsFactory extends EFactory { + /** + * The singleton instance of the factory. + * + * + * @generated + */ + StylesheetsFactory eINSTANCE = org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsFactoryImpl.init(); + + /** + * Returns a new object of class 'Model Style Sheets'. + * + * + * @return a new object of class 'Model Style Sheets'. + * @generated + */ + ModelStyleSheets createModelStyleSheets(); + + /** + * Returns a new object of class 'Style Sheet Reference'. + * + * + * @return a new object of class 'Style Sheet Reference'. + * @generated + */ + StyleSheetReference createStyleSheetReference(); + + /** + * Returns a new object of class 'Embedded Style Sheet'. + * + * + * @return a new object of class 'Embedded Style Sheet'. + * @generated + */ + EmbeddedStyleSheet createEmbeddedStyleSheet(); + + /** + * Returns a new object of class 'Workspace Themes'. + * + * + * @return a new object of class 'Workspace Themes'. + * @generated + */ + WorkspaceThemes createWorkspaceThemes(); + + /** + * Returns a new object of class 'Theme'. + * + * + * @return a new object of class 'Theme'. + * @generated + */ + Theme createTheme(); + + /** + * Returns the package supported by this factory. + * + * + * @return the package supported by this factory. + * @generated + */ + StylesheetsPackage getStylesheetsPackage(); + +} //StylesheetsFactory diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsPackage.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsPackage.java index 60b633b60e6..b751efea329 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsPackage.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/StylesheetsPackage.java @@ -1,361 +1,589 @@ -/** - */ -package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EcorePackage; - -/** - * - * The Package for the model. - * It contains accessors for the meta objects to represent - *

    - *
  • each class,
  • - *
  • each feature of each class,
  • - *
  • each enum,
  • - *
  • and each data type
  • - *
- * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory - * @model kind="package" - * @generated - */ -public interface StylesheetsPackage extends EPackage { - /** - * The package name. - * - * - * @generated - */ - String eNAME = "stylesheets"; - - /** - * The package namespace URI. - * - * - * @generated - */ - String eNS_URI = "http://www.eclipse.org/papyrus/infra/gmfdiag/css"; - - /** - * The package namespace name. - * - * - * @generated - */ - String eNS_PREFIX = "css"; - - /** - * The singleton instance of the package. - * - * - * @generated - */ - StylesheetsPackage eINSTANCE = org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl.init(); - - /** - * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl Model Style Sheets}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getModelStyleSheets() - * @generated - */ - int MODEL_STYLE_SHEETS = 0; - - /** - * The feature id for the 'EAnnotations' containment reference list. - * - * - * @generated - * @ordered - */ - int MODEL_STYLE_SHEETS__EANNOTATIONS = EcorePackage.EMODEL_ELEMENT__EANNOTATIONS; - - /** - * The feature id for the 'Stylesheets' containment reference list. - * - * - * @generated - * @ordered - */ - int MODEL_STYLE_SHEETS__STYLESHEETS = EcorePackage.EMODEL_ELEMENT_FEATURE_COUNT + 0; - - /** - * The number of structural features of the 'Model Style Sheets' class. - * - * - * @generated - * @ordered - */ - int MODEL_STYLE_SHEETS_FEATURE_COUNT = EcorePackage.EMODEL_ELEMENT_FEATURE_COUNT + 1; - - /** - * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheet() - * @generated - */ - int STYLE_SHEET = 1; - - /** - * The number of structural features of the 'Style Sheet' class. - * - * - * @generated - * @ordered - */ - int STYLE_SHEET_FEATURE_COUNT = 0; - - /** - * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl Style Sheet Reference}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheetReference() - * @generated - */ - int STYLE_SHEET_REFERENCE = 2; - - /** - * The feature id for the 'Path' attribute. - * - * - * @generated - * @ordered - */ - int STYLE_SHEET_REFERENCE__PATH = STYLE_SHEET_FEATURE_COUNT + 0; - - /** - * The number of structural features of the 'Style Sheet Reference' class. - * - * - * @generated - * @ordered - */ - int STYLE_SHEET_REFERENCE_FEATURE_COUNT = STYLE_SHEET_FEATURE_COUNT + 1; - - /** - * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl Embedded Style Sheet}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getEmbeddedStyleSheet() - * @generated - */ - int EMBEDDED_STYLE_SHEET = 3; - - /** - * The feature id for the 'Label' attribute. - * - * - * @generated - * @ordered - */ - int EMBEDDED_STYLE_SHEET__LABEL = STYLE_SHEET_FEATURE_COUNT + 0; - - /** - * The feature id for the 'Content' attribute. - * - * - * @generated - * @ordered - */ - int EMBEDDED_STYLE_SHEET__CONTENT = STYLE_SHEET_FEATURE_COUNT + 1; - - /** - * The number of structural features of the 'Embedded Style Sheet' class. - * - * - * @generated - * @ordered - */ - int EMBEDDED_STYLE_SHEET_FEATURE_COUNT = STYLE_SHEET_FEATURE_COUNT + 2; - - - /** - * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets Model Style Sheets}'. - * - * - * @return the meta object for class 'Model Style Sheets'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets - * @generated - */ - EClass getModelStyleSheets(); - - /** - * Returns the meta object for the containment reference list '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets#getStylesheets Stylesheets}'. - * - * - * @return the meta object for the containment reference list 'Stylesheets'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets#getStylesheets() - * @see #getModelStyleSheets() - * @generated - */ - EReference getModelStyleSheets_Stylesheets(); - - /** - * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}'. - * - * - * @return the meta object for class 'Style Sheet'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet - * @generated - */ - EClass getStyleSheet(); - - /** - * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference Style Sheet Reference}'. - * - * - * @return the meta object for class 'Style Sheet Reference'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference - * @generated - */ - EClass getStyleSheetReference(); - - /** - * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference#getPath Path}'. - * - * - * @return the meta object for the attribute 'Path'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference#getPath() - * @see #getStyleSheetReference() - * @generated - */ - EAttribute getStyleSheetReference_Path(); - - /** - * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet Embedded Style Sheet}'. - * - * - * @return the meta object for class 'Embedded Style Sheet'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet - * @generated - */ - EClass getEmbeddedStyleSheet(); - - /** - * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getLabel Label}'. - * - * - * @return the meta object for the attribute 'Label'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getLabel() - * @see #getEmbeddedStyleSheet() - * @generated - */ - EAttribute getEmbeddedStyleSheet_Label(); - - /** - * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getContent Content}'. - * - * - * @return the meta object for the attribute 'Content'. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getContent() - * @see #getEmbeddedStyleSheet() - * @generated - */ - EAttribute getEmbeddedStyleSheet_Content(); - - /** - * Returns the factory that creates the instances of the model. - * - * - * @return the factory that creates the instances of the model. - * @generated - */ - StylesheetsFactory getStylesheetsFactory(); - - /** - * - * Defines literals for the meta objects that represent - *
    - *
  • each class,
  • - *
  • each feature of each class,
  • - *
  • each enum,
  • - *
  • and each data type
  • - *
- * - * @generated - */ - interface Literals { - /** - * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl Model Style Sheets}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getModelStyleSheets() - * @generated - */ - EClass MODEL_STYLE_SHEETS = eINSTANCE.getModelStyleSheets(); - - /** - * The meta object literal for the 'Stylesheets' containment reference list feature. - * - * - * @generated - */ - EReference MODEL_STYLE_SHEETS__STYLESHEETS = eINSTANCE.getModelStyleSheets_Stylesheets(); - - /** - * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheet() - * @generated - */ - EClass STYLE_SHEET = eINSTANCE.getStyleSheet(); - - /** - * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl Style Sheet Reference}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheetReference() - * @generated - */ - EClass STYLE_SHEET_REFERENCE = eINSTANCE.getStyleSheetReference(); - - /** - * The meta object literal for the 'Path' attribute feature. - * - * - * @generated - */ - EAttribute STYLE_SHEET_REFERENCE__PATH = eINSTANCE.getStyleSheetReference_Path(); - - /** - * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl Embedded Style Sheet}' class. - * - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getEmbeddedStyleSheet() - * @generated - */ - EClass EMBEDDED_STYLE_SHEET = eINSTANCE.getEmbeddedStyleSheet(); - - /** - * The meta object literal for the 'Label' attribute feature. - * - * - * @generated - */ - EAttribute EMBEDDED_STYLE_SHEET__LABEL = eINSTANCE.getEmbeddedStyleSheet_Label(); - - /** - * The meta object literal for the 'Content' attribute feature. - * - * - * @generated - */ - EAttribute EMBEDDED_STYLE_SHEET__CONTENT = eINSTANCE.getEmbeddedStyleSheet_Content(); - - } - -} //StylesheetsPackage +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcorePackage; + +/** + * + * The Package for the model. + * It contains accessors for the meta objects to represent + *
    + *
  • each class,
  • + *
  • each feature of each class,
  • + *
  • each enum,
  • + *
  • and each data type
  • + *
+ * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory + * @model kind="package" + * @generated + */ +public interface StylesheetsPackage extends EPackage { + /** + * The package name. + * + * + * @generated + */ + String eNAME = "stylesheets"; + + /** + * The package namespace URI. + * + * + * @generated + */ + String eNS_URI = "http://www.eclipse.org/papyrus/infra/gmfdiag/css"; + + /** + * The package namespace name. + * + * + * @generated + */ + String eNS_PREFIX = "css"; + + /** + * The singleton instance of the package. + * + * + * @generated + */ + StylesheetsPackage eINSTANCE = org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl.init(); + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl Model Style Sheets}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getModelStyleSheets() + * @generated + */ + int MODEL_STYLE_SHEETS = 0; + + /** + * The feature id for the 'EAnnotations' containment reference list. + * + * + * @generated + * @ordered + */ + int MODEL_STYLE_SHEETS__EANNOTATIONS = EcorePackage.EMODEL_ELEMENT__EANNOTATIONS; + + /** + * The feature id for the 'Stylesheets' containment reference list. + * + * + * @generated + * @ordered + */ + int MODEL_STYLE_SHEETS__STYLESHEETS = EcorePackage.EMODEL_ELEMENT_FEATURE_COUNT + 0; + + /** + * The number of structural features of the 'Model Style Sheets' class. + * + * + * @generated + * @ordered + */ + int MODEL_STYLE_SHEETS_FEATURE_COUNT = EcorePackage.EMODEL_ELEMENT_FEATURE_COUNT + 1; + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheet() + * @generated + */ + int STYLE_SHEET = 1; + + /** + * The number of structural features of the 'Style Sheet' class. + * + * + * @generated + * @ordered + */ + int STYLE_SHEET_FEATURE_COUNT = 0; + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl Style Sheet Reference}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheetReference() + * @generated + */ + int STYLE_SHEET_REFERENCE = 2; + + /** + * The feature id for the 'Path' attribute. + * + * + * @generated + * @ordered + */ + int STYLE_SHEET_REFERENCE__PATH = STYLE_SHEET_FEATURE_COUNT + 0; + + /** + * The number of structural features of the 'Style Sheet Reference' class. + * + * + * @generated + * @ordered + */ + int STYLE_SHEET_REFERENCE_FEATURE_COUNT = STYLE_SHEET_FEATURE_COUNT + 1; + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl Embedded Style Sheet}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getEmbeddedStyleSheet() + * @generated + */ + int EMBEDDED_STYLE_SHEET = 3; + + /** + * The feature id for the 'Label' attribute. + * + * + * @generated + * @ordered + */ + int EMBEDDED_STYLE_SHEET__LABEL = STYLE_SHEET_FEATURE_COUNT + 0; + + /** + * The feature id for the 'Content' attribute. + * + * + * @generated + * @ordered + */ + int EMBEDDED_STYLE_SHEET__CONTENT = STYLE_SHEET_FEATURE_COUNT + 1; + + /** + * The number of structural features of the 'Embedded Style Sheet' class. + * + * + * @generated + * @ordered + */ + int EMBEDDED_STYLE_SHEET_FEATURE_COUNT = STYLE_SHEET_FEATURE_COUNT + 2; + + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.WorkspaceThemesImpl Workspace Themes}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.WorkspaceThemesImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getWorkspaceThemes() + * @generated + */ + int WORKSPACE_THEMES = 4; + + /** + * The feature id for the 'EAnnotations' containment reference list. + * + * + * @generated + * @ordered + */ + int WORKSPACE_THEMES__EANNOTATIONS = EcorePackage.EMODEL_ELEMENT__EANNOTATIONS; + + /** + * The feature id for the 'Themes' containment reference list. + * + * + * @generated + * @ordered + */ + int WORKSPACE_THEMES__THEMES = EcorePackage.EMODEL_ELEMENT_FEATURE_COUNT + 0; + + /** + * The number of structural features of the 'Workspace Themes' class. + * + * + * @generated + * @ordered + */ + int WORKSPACE_THEMES_FEATURE_COUNT = EcorePackage.EMODEL_ELEMENT_FEATURE_COUNT + 1; + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl Theme}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getTheme() + * @generated + */ + int THEME = 5; + + /** + * The feature id for the 'Id' attribute. + * + * + * @generated + * @ordered + */ + int THEME__ID = 0; + + /** + * The feature id for the 'Label' attribute. + * + * + * @generated + * @ordered + */ + int THEME__LABEL = 1; + + /** + * The feature id for the 'Icon' attribute. + * + * + * @generated + * @ordered + */ + int THEME__ICON = 2; + + /** + * The feature id for the 'Stylesheets' containment reference list. + * + * + * @generated + * @ordered + */ + int THEME__STYLESHEETS = 3; + + /** + * The number of structural features of the 'Theme' class. + * + * + * @generated + * @ordered + */ + int THEME_FEATURE_COUNT = 4; + + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets Model Style Sheets}'. + * + * + * @return the meta object for class 'Model Style Sheets'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets + * @generated + */ + EClass getModelStyleSheets(); + + /** + * Returns the meta object for the containment reference list '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets#getStylesheets Stylesheets}'. + * + * + * @return the meta object for the containment reference list 'Stylesheets'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets#getStylesheets() + * @see #getModelStyleSheets() + * @generated + */ + EReference getModelStyleSheets_Stylesheets(); + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}'. + * + * + * @return the meta object for class 'Style Sheet'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet + * @generated + */ + EClass getStyleSheet(); + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference Style Sheet Reference}'. + * + * + * @return the meta object for class 'Style Sheet Reference'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference + * @generated + */ + EClass getStyleSheetReference(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference#getPath Path}'. + * + * + * @return the meta object for the attribute 'Path'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference#getPath() + * @see #getStyleSheetReference() + * @generated + */ + EAttribute getStyleSheetReference_Path(); + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet Embedded Style Sheet}'. + * + * + * @return the meta object for class 'Embedded Style Sheet'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet + * @generated + */ + EClass getEmbeddedStyleSheet(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getLabel Label}'. + * + * + * @return the meta object for the attribute 'Label'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getLabel() + * @see #getEmbeddedStyleSheet() + * @generated + */ + EAttribute getEmbeddedStyleSheet_Label(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getContent Content}'. + * + * + * @return the meta object for the attribute 'Content'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet#getContent() + * @see #getEmbeddedStyleSheet() + * @generated + */ + EAttribute getEmbeddedStyleSheet_Content(); + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes Workspace Themes}'. + * + * + * @return the meta object for class 'Workspace Themes'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes + * @generated + */ + EClass getWorkspaceThemes(); + + /** + * Returns the meta object for the containment reference list '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes#getThemes Themes}'. + * + * + * @return the meta object for the containment reference list 'Themes'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes#getThemes() + * @see #getWorkspaceThemes() + * @generated + */ + EReference getWorkspaceThemes_Themes(); + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme Theme}'. + * + * + * @return the meta object for class 'Theme'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme + * @generated + */ + EClass getTheme(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getId Id}'. + * + * + * @return the meta object for the attribute 'Id'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getId() + * @see #getTheme() + * @generated + */ + EAttribute getTheme_Id(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getLabel Label}'. + * + * + * @return the meta object for the attribute 'Label'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getLabel() + * @see #getTheme() + * @generated + */ + EAttribute getTheme_Label(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getIcon Icon}'. + * + * + * @return the meta object for the attribute 'Icon'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getIcon() + * @see #getTheme() + * @generated + */ + EAttribute getTheme_Icon(); + + /** + * Returns the meta object for the containment reference list '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getStylesheets Stylesheets}'. + * + * + * @return the meta object for the containment reference list 'Stylesheets'. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getStylesheets() + * @see #getTheme() + * @generated + */ + EReference getTheme_Stylesheets(); + + /** + * Returns the factory that creates the instances of the model. + * + * + * @return the factory that creates the instances of the model. + * @generated + */ + StylesheetsFactory getStylesheetsFactory(); + + /** + * + * Defines literals for the meta objects that represent + *
    + *
  • each class,
  • + *
  • each feature of each class,
  • + *
  • each enum,
  • + *
  • and each data type
  • + *
+ * + * @generated + */ + interface Literals { + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl Model Style Sheets}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ModelStyleSheetsImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getModelStyleSheets() + * @generated + */ + EClass MODEL_STYLE_SHEETS = eINSTANCE.getModelStyleSheets(); + + /** + * The meta object literal for the 'Stylesheets' containment reference list feature. + * + * + * @generated + */ + EReference MODEL_STYLE_SHEETS__STYLESHEETS = eINSTANCE.getModelStyleSheets_Stylesheets(); + + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheet() + * @generated + */ + EClass STYLE_SHEET = eINSTANCE.getStyleSheet(); + + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl Style Sheet Reference}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StyleSheetReferenceImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getStyleSheetReference() + * @generated + */ + EClass STYLE_SHEET_REFERENCE = eINSTANCE.getStyleSheetReference(); + + /** + * The meta object literal for the 'Path' attribute feature. + * + * + * @generated + */ + EAttribute STYLE_SHEET_REFERENCE__PATH = eINSTANCE.getStyleSheetReference_Path(); + + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl Embedded Style Sheet}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.EmbeddedStyleSheetImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getEmbeddedStyleSheet() + * @generated + */ + EClass EMBEDDED_STYLE_SHEET = eINSTANCE.getEmbeddedStyleSheet(); + + /** + * The meta object literal for the 'Label' attribute feature. + * + * + * @generated + */ + EAttribute EMBEDDED_STYLE_SHEET__LABEL = eINSTANCE.getEmbeddedStyleSheet_Label(); + + /** + * The meta object literal for the 'Content' attribute feature. + * + * + * @generated + */ + EAttribute EMBEDDED_STYLE_SHEET__CONTENT = eINSTANCE.getEmbeddedStyleSheet_Content(); + + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.WorkspaceThemesImpl Workspace Themes}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.WorkspaceThemesImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getWorkspaceThemes() + * @generated + */ + EClass WORKSPACE_THEMES = eINSTANCE.getWorkspaceThemes(); + + /** + * The meta object literal for the 'Themes' containment reference list feature. + * + * + * @generated + */ + EReference WORKSPACE_THEMES__THEMES = eINSTANCE.getWorkspaceThemes_Themes(); + + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl Theme}' class. + * + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.StylesheetsPackageImpl#getTheme() + * @generated + */ + EClass THEME = eINSTANCE.getTheme(); + + /** + * The meta object literal for the 'Id' attribute feature. + * + * + * @generated + */ + EAttribute THEME__ID = eINSTANCE.getTheme_Id(); + + /** + * The meta object literal for the 'Label' attribute feature. + * + * + * @generated + */ + EAttribute THEME__LABEL = eINSTANCE.getTheme_Label(); + + /** + * The meta object literal for the 'Icon' attribute feature. + * + * + * @generated + */ + EAttribute THEME__ICON = eINSTANCE.getTheme_Icon(); + + /** + * The meta object literal for the 'Stylesheets' containment reference list feature. + * + * + * @generated + */ + EReference THEME__STYLESHEETS = eINSTANCE.getTheme_Stylesheets(); + + } + +} //StylesheetsPackage diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/Theme.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/Theme.java new file mode 100644 index 00000000000..2fa8740556f --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/Theme.java @@ -0,0 +1,123 @@ +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; + +/** + * + * A representation of the model object 'Theme'. + * + * + *

+ * The following features are supported: + *

    + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getId Id}
  • + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getLabel Label}
  • + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getIcon Icon}
  • + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getStylesheets Stylesheets}
  • + *
+ *

+ * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getTheme() + * @model + * @generated + */ +public interface Theme extends EObject { + /** + * Returns the value of the 'Id' attribute. + * The default value is "". + * + *

+ * If the meaning of the 'Id' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Id' attribute. + * @see #setId(String) + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getTheme_Id() + * @model default="" id="true" ordered="false" + * @generated + */ + String getId(); + + /** + * Sets the value of the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getId Id}' attribute. + * + * + * @param value the new value of the 'Id' attribute. + * @see #getId() + * @generated + */ + void setId(String value); + + /** + * Returns the value of the 'Label' attribute. + * + *

+ * If the meaning of the 'Label' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Label' attribute. + * @see #setLabel(String) + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getTheme_Label() + * @model + * @generated + */ + String getLabel(); + + /** + * Sets the value of the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getLabel Label}' attribute. + * + * + * @param value the new value of the 'Label' attribute. + * @see #getLabel() + * @generated + */ + void setLabel(String value); + + /** + * Returns the value of the 'Icon' attribute. + * + *

+ * If the meaning of the 'Icon' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Icon' attribute. + * @see #setIcon(String) + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getTheme_Icon() + * @model + * @generated + */ + String getIcon(); + + /** + * Sets the value of the '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme#getIcon Icon}' attribute. + * + * + * @param value the new value of the 'Icon' attribute. + * @see #getIcon() + * @generated + */ + void setIcon(String value); + + /** + * Returns the value of the 'Stylesheets' containment reference list. + * The list contents are of type {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet}. + * + *

+ * If the meaning of the 'Stylesheets' reference list isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Stylesheets' containment reference list. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getTheme_Stylesheets() + * @model containment="true" + * @generated + */ + EList getStylesheets(); + +} // Theme diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/WorkspaceThemes.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/WorkspaceThemes.java new file mode 100644 index 00000000000..5b5788be417 --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/WorkspaceThemes.java @@ -0,0 +1,42 @@ +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets; + +import org.eclipse.emf.common.util.EList; + +import org.eclipse.emf.ecore.EModelElement; + +/** + * + * A representation of the model object 'Workspace Themes'. + * + * + *

+ * The following features are supported: + *

    + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes#getThemes Themes}
  • + *
+ *

+ * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getWorkspaceThemes() + * @model + * @generated + */ +public interface WorkspaceThemes extends EModelElement { + /** + * Returns the value of the 'Themes' containment reference list. + * The list contents are of type {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme}. + * + *

+ * If the meaning of the 'Themes' reference list isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Themes' containment reference list. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#getWorkspaceThemes_Themes() + * @model containment="true" + * @generated + */ + EList getThemes(); + +} // WorkspaceThemes diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsFactoryImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsFactoryImpl.java index 2615679a45d..3ce954461d3 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsFactoryImpl.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsFactoryImpl.java @@ -1,118 +1,141 @@ -/** - */ -package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.impl.EFactoryImpl; -import org.eclipse.emf.ecore.plugin.EcorePlugin; -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.StyleSheetReference; -import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory; -import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; - -/** - * - * An implementation of the model Factory. - * - * @generated - */ -public class StylesheetsFactoryImpl extends EFactoryImpl implements StylesheetsFactory { - /** - * Creates the default factory implementation. - * - * - * @generated - */ - public static StylesheetsFactory init() { - try { - StylesheetsFactory theStylesheetsFactory = (StylesheetsFactory)EPackage.Registry.INSTANCE.getEFactory("http://www.eclipse.org/papyrus/infra/gmfdiag/css"); - if (theStylesheetsFactory != null) { - return theStylesheetsFactory; - } - } - catch (Exception exception) { - EcorePlugin.INSTANCE.log(exception); - } - return new StylesheetsFactoryImpl(); - } - - /** - * Creates an instance of the factory. - * - * - * @generated - */ - public StylesheetsFactoryImpl() { - super(); - } - - /** - * - * - * @generated - */ - @Override - public EObject create(EClass eClass) { - switch (eClass.getClassifierID()) { - case StylesheetsPackage.MODEL_STYLE_SHEETS: return createModelStyleSheets(); - case StylesheetsPackage.STYLE_SHEET_REFERENCE: return createStyleSheetReference(); - case StylesheetsPackage.EMBEDDED_STYLE_SHEET: return createEmbeddedStyleSheet(); - default: - throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); - } - } - - /** - * - * - * @generated - */ - public ModelStyleSheets createModelStyleSheets() { - ModelStyleSheetsImpl modelStyleSheets = new ModelStyleSheetsImpl(); - return modelStyleSheets; - } - - /** - * - * - * @generated - */ - public StyleSheetReference createStyleSheetReference() { - StyleSheetReferenceImpl styleSheetReference = new StyleSheetReferenceImpl(); - return styleSheetReference; - } - - /** - * - * - * @generated - */ - public EmbeddedStyleSheet createEmbeddedStyleSheet() { - EmbeddedStyleSheetImpl embeddedStyleSheet = new EmbeddedStyleSheetImpl(); - return embeddedStyleSheet; - } - - /** - * - * - * @generated - */ - public StylesheetsPackage getStylesheetsPackage() { - return (StylesheetsPackage)getEPackage(); - } - - /** - * - * - * @deprecated - * @generated - */ - @Deprecated - public static StylesheetsPackage getPackage() { - return StylesheetsPackage.eINSTANCE; - } - -} //StylesheetsFactoryImpl +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.EFactoryImpl; +import org.eclipse.emf.ecore.plugin.EcorePlugin; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.*; +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.StyleSheetReference; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; + +/** + * + * An implementation of the model Factory. + * + * @generated + */ +public class StylesheetsFactoryImpl extends EFactoryImpl implements StylesheetsFactory { + /** + * Creates the default factory implementation. + * + * + * @generated + */ + public static StylesheetsFactory init() { + try { + StylesheetsFactory theStylesheetsFactory = (StylesheetsFactory)EPackage.Registry.INSTANCE.getEFactory(StylesheetsPackage.eNS_URI); + if (theStylesheetsFactory != null) { + return theStylesheetsFactory; + } + } + catch (Exception exception) { + EcorePlugin.INSTANCE.log(exception); + } + return new StylesheetsFactoryImpl(); + } + + /** + * Creates an instance of the factory. + * + * + * @generated + */ + public StylesheetsFactoryImpl() { + super(); + } + + /** + * + * + * @generated + */ + @Override + public EObject create(EClass eClass) { + switch (eClass.getClassifierID()) { + case StylesheetsPackage.MODEL_STYLE_SHEETS: return createModelStyleSheets(); + case StylesheetsPackage.STYLE_SHEET_REFERENCE: return createStyleSheetReference(); + case StylesheetsPackage.EMBEDDED_STYLE_SHEET: return createEmbeddedStyleSheet(); + case StylesheetsPackage.WORKSPACE_THEMES: return createWorkspaceThemes(); + case StylesheetsPackage.THEME: return createTheme(); + default: + throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); + } + } + + /** + * + * + * @generated + */ + public ModelStyleSheets createModelStyleSheets() { + ModelStyleSheetsImpl modelStyleSheets = new ModelStyleSheetsImpl(); + return modelStyleSheets; + } + + /** + * + * + * @generated + */ + public StyleSheetReference createStyleSheetReference() { + StyleSheetReferenceImpl styleSheetReference = new StyleSheetReferenceImpl(); + return styleSheetReference; + } + + /** + * + * + * @generated + */ + public EmbeddedStyleSheet createEmbeddedStyleSheet() { + EmbeddedStyleSheetImpl embeddedStyleSheet = new EmbeddedStyleSheetImpl(); + return embeddedStyleSheet; + } + + /** + * + * + * @generated + */ + public WorkspaceThemes createWorkspaceThemes() { + WorkspaceThemesImpl workspaceThemes = new WorkspaceThemesImpl(); + return workspaceThemes; + } + + /** + * + * + * @generated + */ + public Theme createTheme() { + ThemeImpl theme = new ThemeImpl(); + return theme; + } + + /** + * + * + * @generated + */ + public StylesheetsPackage getStylesheetsPackage() { + return (StylesheetsPackage)getEPackage(); + } + + /** + * + * + * @deprecated + * @generated + */ + @Deprecated + public static StylesheetsPackage getPackage() { + return StylesheetsPackage.eINSTANCE; + } + +} //StylesheetsFactoryImpl diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsPackageImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsPackageImpl.java index be80aa96a8c..f8647b47283 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsPackageImpl.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/StylesheetsPackageImpl.java @@ -1,282 +1,380 @@ -/** - */ -package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.impl.EPackageImpl; -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.StylesheetsFactory; -import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; - -/** - * - * An implementation of the model Package. - * - * @generated - */ -public class StylesheetsPackageImpl extends EPackageImpl implements StylesheetsPackage { - /** - * - * - * @generated - */ - private EClass modelStyleSheetsEClass = null; - - /** - * - * - * @generated - */ - private EClass styleSheetEClass = null; - - /** - * - * - * @generated - */ - private EClass styleSheetReferenceEClass = null; - - /** - * - * - * @generated - */ - private EClass embeddedStyleSheetEClass = null; - - /** - * Creates an instance of the model Package, registered with - * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package - * package URI value. - *

Note: the correct way to create the package is via the static - * factory method {@link #init init()}, which also performs - * initialization of the package, or returns the registered package, - * if one already exists. - * - * - * @see org.eclipse.emf.ecore.EPackage.Registry - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#eNS_URI - * @see #init() - * @generated - */ - private StylesheetsPackageImpl() { - super(eNS_URI, StylesheetsFactory.eINSTANCE); - } - - /** - * - * - * @generated - */ - private static boolean isInited = false; - - /** - * Creates, registers, and initializes the Package for this model, and for any others upon which it depends. - * - *

This method is used to initialize {@link StylesheetsPackage#eINSTANCE} when that field is accessed. - * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package. - * - * - * @see #eNS_URI - * @see #createPackageContents() - * @see #initializePackageContents() - * @generated - */ - public static StylesheetsPackage init() { - if (isInited) return (StylesheetsPackage)EPackage.Registry.INSTANCE.getEPackage(StylesheetsPackage.eNS_URI); - - // Obtain or create and register package - StylesheetsPackageImpl theStylesheetsPackage = (StylesheetsPackageImpl)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof StylesheetsPackageImpl ? EPackage.Registry.INSTANCE.get(eNS_URI) : new StylesheetsPackageImpl()); - - isInited = true; - - // Initialize simple dependencies - EcorePackage.eINSTANCE.eClass(); - - // Create package meta-data objects - theStylesheetsPackage.createPackageContents(); - - // Initialize created meta-data - theStylesheetsPackage.initializePackageContents(); - - // Mark meta-data to indicate it can't be changed - theStylesheetsPackage.freeze(); - - - // Update the registry and return the package - EPackage.Registry.INSTANCE.put(StylesheetsPackage.eNS_URI, theStylesheetsPackage); - return theStylesheetsPackage; - } - - /** - * - * - * @generated - */ - public EClass getModelStyleSheets() { - return modelStyleSheetsEClass; - } - - /** - * - * - * @generated - */ - public EReference getModelStyleSheets_Stylesheets() { - return (EReference)modelStyleSheetsEClass.getEStructuralFeatures().get(0); - } - - /** - * - * - * @generated - */ - public EClass getStyleSheet() { - return styleSheetEClass; - } - - /** - * - * - * @generated - */ - public EClass getStyleSheetReference() { - return styleSheetReferenceEClass; - } - - /** - * - * - * @generated - */ - public EAttribute getStyleSheetReference_Path() { - return (EAttribute)styleSheetReferenceEClass.getEStructuralFeatures().get(0); - } - - /** - * - * - * @generated - */ - public EClass getEmbeddedStyleSheet() { - return embeddedStyleSheetEClass; - } - - /** - * - * - * @generated - */ - public EAttribute getEmbeddedStyleSheet_Label() { - return (EAttribute)embeddedStyleSheetEClass.getEStructuralFeatures().get(0); - } - - /** - * - * - * @generated - */ - public EAttribute getEmbeddedStyleSheet_Content() { - return (EAttribute)embeddedStyleSheetEClass.getEStructuralFeatures().get(1); - } - - /** - * - * - * @generated - */ - public StylesheetsFactory getStylesheetsFactory() { - return (StylesheetsFactory)getEFactoryInstance(); - } - - /** - * - * - * @generated - */ - private boolean isCreated = false; - - /** - * Creates the meta-model objects for the package. This method is - * guarded to have no affect on any invocation but its first. - * - * - * @generated - */ - public void createPackageContents() { - if (isCreated) return; - isCreated = true; - - // Create classes and their features - modelStyleSheetsEClass = createEClass(MODEL_STYLE_SHEETS); - createEReference(modelStyleSheetsEClass, MODEL_STYLE_SHEETS__STYLESHEETS); - - styleSheetEClass = createEClass(STYLE_SHEET); - - styleSheetReferenceEClass = createEClass(STYLE_SHEET_REFERENCE); - createEAttribute(styleSheetReferenceEClass, STYLE_SHEET_REFERENCE__PATH); - - embeddedStyleSheetEClass = createEClass(EMBEDDED_STYLE_SHEET); - createEAttribute(embeddedStyleSheetEClass, EMBEDDED_STYLE_SHEET__LABEL); - createEAttribute(embeddedStyleSheetEClass, EMBEDDED_STYLE_SHEET__CONTENT); - } - - /** - * - * - * @generated - */ - private boolean isInitialized = false; - - /** - * Complete the initialization of the package and its meta-model. This - * method is guarded to have no affect on any invocation but its first. - * - * - * @generated - */ - public void initializePackageContents() { - if (isInitialized) return; - isInitialized = true; - - // Initialize package - setName(eNAME); - setNsPrefix(eNS_PREFIX); - setNsURI(eNS_URI); - - // Obtain other dependent packages - EcorePackage theEcorePackage = (EcorePackage)EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI); - - // Create type parameters - - // Set bounds for type parameters - - // Add supertypes to classes - modelStyleSheetsEClass.getESuperTypes().add(theEcorePackage.getEModelElement()); - styleSheetReferenceEClass.getESuperTypes().add(this.getStyleSheet()); - embeddedStyleSheetEClass.getESuperTypes().add(this.getStyleSheet()); - - // Initialize classes and features; add operations and parameters - initEClass(modelStyleSheetsEClass, ModelStyleSheets.class, "ModelStyleSheets", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEReference(getModelStyleSheets_Stylesheets(), this.getStyleSheet(), null, "stylesheets", null, 0, -1, ModelStyleSheets.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - - initEClass(styleSheetEClass, StyleSheet.class, "StyleSheet", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - - initEClass(styleSheetReferenceEClass, StyleSheetReference.class, "StyleSheetReference", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEAttribute(getStyleSheetReference_Path(), theEcorePackage.getEString(), "path", null, 1, 1, StyleSheetReference.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - - initEClass(embeddedStyleSheetEClass, EmbeddedStyleSheet.class, "EmbeddedStyleSheet", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEAttribute(getEmbeddedStyleSheet_Label(), ecorePackage.getEString(), "label", null, 0, 1, EmbeddedStyleSheet.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - initEAttribute(getEmbeddedStyleSheet_Content(), theEcorePackage.getEString(), "content", null, 1, 1, EmbeddedStyleSheet.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - - // Create resource - createResource(eNS_URI); - } - -} //StylesheetsPackageImpl +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.impl.EPackageImpl; +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.StylesheetsFactory; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes; + +/** + * + * An implementation of the model Package. + * + * @generated + */ +public class StylesheetsPackageImpl extends EPackageImpl implements StylesheetsPackage { + /** + * + * + * @generated + */ + private EClass modelStyleSheetsEClass = null; + + /** + * + * + * @generated + */ + private EClass styleSheetEClass = null; + + /** + * + * + * @generated + */ + private EClass styleSheetReferenceEClass = null; + + /** + * + * + * @generated + */ + private EClass embeddedStyleSheetEClass = null; + + /** + * + * + * @generated + */ + private EClass workspaceThemesEClass = null; + + /** + * + * + * @generated + */ + private EClass themeEClass = null; + + /** + * Creates an instance of the model Package, registered with + * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package + * package URI value. + *

Note: the correct way to create the package is via the static + * factory method {@link #init init()}, which also performs + * initialization of the package, or returns the registered package, + * if one already exists. + * + * + * @see org.eclipse.emf.ecore.EPackage.Registry + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage#eNS_URI + * @see #init() + * @generated + */ + private StylesheetsPackageImpl() { + super(eNS_URI, StylesheetsFactory.eINSTANCE); + } + + /** + * + * + * @generated + */ + private static boolean isInited = false; + + /** + * Creates, registers, and initializes the Package for this model, and for any others upon which it depends. + * + *

This method is used to initialize {@link StylesheetsPackage#eINSTANCE} when that field is accessed. + * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package. + * + * + * @see #eNS_URI + * @see #createPackageContents() + * @see #initializePackageContents() + * @generated + */ + public static StylesheetsPackage init() { + if (isInited) return (StylesheetsPackage)EPackage.Registry.INSTANCE.getEPackage(StylesheetsPackage.eNS_URI); + + // Obtain or create and register package + StylesheetsPackageImpl theStylesheetsPackage = (StylesheetsPackageImpl)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof StylesheetsPackageImpl ? EPackage.Registry.INSTANCE.get(eNS_URI) : new StylesheetsPackageImpl()); + + isInited = true; + + // Initialize simple dependencies + EcorePackage.eINSTANCE.eClass(); + + // Create package meta-data objects + theStylesheetsPackage.createPackageContents(); + + // Initialize created meta-data + theStylesheetsPackage.initializePackageContents(); + + // Mark meta-data to indicate it can't be changed + theStylesheetsPackage.freeze(); + + + // Update the registry and return the package + EPackage.Registry.INSTANCE.put(StylesheetsPackage.eNS_URI, theStylesheetsPackage); + return theStylesheetsPackage; + } + + /** + * + * + * @generated + */ + public EClass getModelStyleSheets() { + return modelStyleSheetsEClass; + } + + /** + * + * + * @generated + */ + public EReference getModelStyleSheets_Stylesheets() { + return (EReference)modelStyleSheetsEClass.getEStructuralFeatures().get(0); + } + + /** + * + * + * @generated + */ + public EClass getStyleSheet() { + return styleSheetEClass; + } + + /** + * + * + * @generated + */ + public EClass getStyleSheetReference() { + return styleSheetReferenceEClass; + } + + /** + * + * + * @generated + */ + public EAttribute getStyleSheetReference_Path() { + return (EAttribute)styleSheetReferenceEClass.getEStructuralFeatures().get(0); + } + + /** + * + * + * @generated + */ + public EClass getEmbeddedStyleSheet() { + return embeddedStyleSheetEClass; + } + + /** + * + * + * @generated + */ + public EAttribute getEmbeddedStyleSheet_Label() { + return (EAttribute)embeddedStyleSheetEClass.getEStructuralFeatures().get(0); + } + + /** + * + * + * @generated + */ + public EAttribute getEmbeddedStyleSheet_Content() { + return (EAttribute)embeddedStyleSheetEClass.getEStructuralFeatures().get(1); + } + + /** + * + * + * @generated + */ + public EClass getWorkspaceThemes() { + return workspaceThemesEClass; + } + + /** + * + * + * @generated + */ + public EReference getWorkspaceThemes_Themes() { + return (EReference)workspaceThemesEClass.getEStructuralFeatures().get(0); + } + + /** + * + * + * @generated + */ + public EClass getTheme() { + return themeEClass; + } + + /** + * + * + * @generated + */ + public EAttribute getTheme_Id() { + return (EAttribute)themeEClass.getEStructuralFeatures().get(0); + } + + /** + * + * + * @generated + */ + public EAttribute getTheme_Label() { + return (EAttribute)themeEClass.getEStructuralFeatures().get(1); + } + + /** + * + * + * @generated + */ + public EAttribute getTheme_Icon() { + return (EAttribute)themeEClass.getEStructuralFeatures().get(2); + } + + /** + * + * + * @generated + */ + public EReference getTheme_Stylesheets() { + return (EReference)themeEClass.getEStructuralFeatures().get(3); + } + + /** + * + * + * @generated + */ + public StylesheetsFactory getStylesheetsFactory() { + return (StylesheetsFactory)getEFactoryInstance(); + } + + /** + * + * + * @generated + */ + private boolean isCreated = false; + + /** + * Creates the meta-model objects for the package. This method is + * guarded to have no affect on any invocation but its first. + * + * + * @generated + */ + public void createPackageContents() { + if (isCreated) return; + isCreated = true; + + // Create classes and their features + modelStyleSheetsEClass = createEClass(MODEL_STYLE_SHEETS); + createEReference(modelStyleSheetsEClass, MODEL_STYLE_SHEETS__STYLESHEETS); + + styleSheetEClass = createEClass(STYLE_SHEET); + + styleSheetReferenceEClass = createEClass(STYLE_SHEET_REFERENCE); + createEAttribute(styleSheetReferenceEClass, STYLE_SHEET_REFERENCE__PATH); + + embeddedStyleSheetEClass = createEClass(EMBEDDED_STYLE_SHEET); + createEAttribute(embeddedStyleSheetEClass, EMBEDDED_STYLE_SHEET__LABEL); + createEAttribute(embeddedStyleSheetEClass, EMBEDDED_STYLE_SHEET__CONTENT); + + workspaceThemesEClass = createEClass(WORKSPACE_THEMES); + createEReference(workspaceThemesEClass, WORKSPACE_THEMES__THEMES); + + themeEClass = createEClass(THEME); + createEAttribute(themeEClass, THEME__ID); + createEAttribute(themeEClass, THEME__LABEL); + createEAttribute(themeEClass, THEME__ICON); + createEReference(themeEClass, THEME__STYLESHEETS); + } + + /** + * + * + * @generated + */ + private boolean isInitialized = false; + + /** + * Complete the initialization of the package and its meta-model. This + * method is guarded to have no affect on any invocation but its first. + * + * + * @generated + */ + public void initializePackageContents() { + if (isInitialized) return; + isInitialized = true; + + // Initialize package + setName(eNAME); + setNsPrefix(eNS_PREFIX); + setNsURI(eNS_URI); + + // Obtain other dependent packages + EcorePackage theEcorePackage = (EcorePackage)EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI); + + // Create type parameters + + // Set bounds for type parameters + + // Add supertypes to classes + modelStyleSheetsEClass.getESuperTypes().add(theEcorePackage.getEModelElement()); + styleSheetReferenceEClass.getESuperTypes().add(this.getStyleSheet()); + embeddedStyleSheetEClass.getESuperTypes().add(this.getStyleSheet()); + workspaceThemesEClass.getESuperTypes().add(theEcorePackage.getEModelElement()); + + // Initialize classes and features; add operations and parameters + initEClass(modelStyleSheetsEClass, ModelStyleSheets.class, "ModelStyleSheets", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEReference(getModelStyleSheets_Stylesheets(), this.getStyleSheet(), null, "stylesheets", null, 0, -1, ModelStyleSheets.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + initEClass(styleSheetEClass, StyleSheet.class, "StyleSheet", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + + initEClass(styleSheetReferenceEClass, StyleSheetReference.class, "StyleSheetReference", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getStyleSheetReference_Path(), theEcorePackage.getEString(), "path", null, 1, 1, StyleSheetReference.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + initEClass(embeddedStyleSheetEClass, EmbeddedStyleSheet.class, "EmbeddedStyleSheet", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getEmbeddedStyleSheet_Label(), ecorePackage.getEString(), "label", null, 0, 1, EmbeddedStyleSheet.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getEmbeddedStyleSheet_Content(), theEcorePackage.getEString(), "content", null, 1, 1, EmbeddedStyleSheet.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + initEClass(workspaceThemesEClass, WorkspaceThemes.class, "WorkspaceThemes", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEReference(getWorkspaceThemes_Themes(), this.getTheme(), null, "themes", null, 0, -1, WorkspaceThemes.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + initEClass(themeEClass, Theme.class, "Theme", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getTheme_Id(), theEcorePackage.getEString(), "id", "", 0, 1, Theme.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, IS_ID, IS_UNIQUE, !IS_DERIVED, !IS_ORDERED); + initEAttribute(getTheme_Label(), theEcorePackage.getEString(), "label", null, 0, 1, Theme.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getTheme_Icon(), theEcorePackage.getEString(), "icon", null, 0, 1, Theme.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getTheme_Stylesheets(), this.getStyleSheet(), null, "stylesheets", null, 0, -1, Theme.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + // Create resource + createResource(eNS_URI); + } + +} //StylesheetsPackageImpl diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/ThemeImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/ThemeImpl.java new file mode 100644 index 00000000000..3b2fe7bb3a8 --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/ThemeImpl.java @@ -0,0 +1,327 @@ +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl; + +import java.util.Collection; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.NotificationChain; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.emf.ecore.impl.EObjectImpl; +import org.eclipse.emf.ecore.util.EObjectContainmentEList; +import org.eclipse.emf.ecore.util.EObjectResolvingEList; +import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; + +/** + * + * An implementation of the model object 'Theme'. + * + *

+ * The following features are implemented: + *

    + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl#getId Id}
  • + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl#getLabel Label}
  • + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl#getIcon Icon}
  • + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.ThemeImpl#getStylesheets Stylesheets}
  • + *
+ *

+ * + * @generated + */ +public class ThemeImpl extends EObjectImpl implements Theme { + + /** + * The default value of the '{@link #getId() Id}' attribute. + * + * + * @see #getId() + * @generated + * @ordered + */ + protected static final String ID_EDEFAULT = ""; + + /** + * The cached value of the '{@link #getId() Id}' attribute. + * + * + * @see #getId() + * @generated + * @ordered + */ + protected String id = ID_EDEFAULT; + + /** + * The default value of the '{@link #getLabel() Label}' attribute. + * + * + * @see #getLabel() + * @generated + * @ordered + */ + protected static final String LABEL_EDEFAULT = null; + + /** + * The cached value of the '{@link #getLabel() Label}' attribute. + * + * + * @see #getLabel() + * @generated + * @ordered + */ + protected String label = LABEL_EDEFAULT; + + /** + * The default value of the '{@link #getIcon() Icon}' attribute. + * + * + * @see #getIcon() + * @generated + * @ordered + */ + protected static final String ICON_EDEFAULT = null; + + /** + * The cached value of the '{@link #getIcon() Icon}' attribute. + * + * + * @see #getIcon() + * @generated + * @ordered + */ + protected String icon = ICON_EDEFAULT; + + /** + * The cached value of the '{@link #getStylesheets() Stylesheets}' containment reference list. + * + * + * @see #getStylesheets() + * @generated + * @ordered + */ + protected EList stylesheets; + + /** + * + * + * @generated + */ + protected ThemeImpl() { + super(); + } + + /** + * + * + * @generated + */ + @Override + protected EClass eStaticClass() { + return StylesheetsPackage.Literals.THEME; + } + + /** + * + * + * @generated + */ + public String getId() { + return id; + } + + /** + * + * + * @generated + */ + public void setId(String newId) { + String oldId = id; + id = newId; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, StylesheetsPackage.THEME__ID, oldId, id)); + } + + /** + * + * + * @generated + */ + public String getLabel() { + return label; + } + + /** + * + * + * @generated + */ + public void setLabel(String newLabel) { + String oldLabel = label; + label = newLabel; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, StylesheetsPackage.THEME__LABEL, oldLabel, label)); + } + + /** + * + * + * @generated + */ + public String getIcon() { + return icon; + } + + /** + * + * + * @generated + */ + public void setIcon(String newIcon) { + String oldIcon = icon; + icon = newIcon; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, StylesheetsPackage.THEME__ICON, oldIcon, icon)); + } + + /** + * + * + * @generated + */ + public EList getStylesheets() { + if (stylesheets == null) { + stylesheets = new EObjectContainmentEList(StyleSheet.class, this, StylesheetsPackage.THEME__STYLESHEETS); + } + return stylesheets; + } + + /** + * + * + * @generated + */ + @Override + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case StylesheetsPackage.THEME__STYLESHEETS: + return ((InternalEList)getStylesheets()).basicRemove(otherEnd, msgs); + } + return super.eInverseRemove(otherEnd, featureID, msgs); + } + + /** + * + * + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case StylesheetsPackage.THEME__ID: + return getId(); + case StylesheetsPackage.THEME__LABEL: + return getLabel(); + case StylesheetsPackage.THEME__ICON: + return getIcon(); + case StylesheetsPackage.THEME__STYLESHEETS: + return getStylesheets(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * + * + * @generated + */ + @SuppressWarnings("unchecked") + @Override + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case StylesheetsPackage.THEME__ID: + setId((String)newValue); + return; + case StylesheetsPackage.THEME__LABEL: + setLabel((String)newValue); + return; + case StylesheetsPackage.THEME__ICON: + setIcon((String)newValue); + return; + case StylesheetsPackage.THEME__STYLESHEETS: + getStylesheets().clear(); + getStylesheets().addAll((Collection)newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * + * + * @generated + */ + @Override + public void eUnset(int featureID) { + switch (featureID) { + case StylesheetsPackage.THEME__ID: + setId(ID_EDEFAULT); + return; + case StylesheetsPackage.THEME__LABEL: + setLabel(LABEL_EDEFAULT); + return; + case StylesheetsPackage.THEME__ICON: + setIcon(ICON_EDEFAULT); + return; + case StylesheetsPackage.THEME__STYLESHEETS: + getStylesheets().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * + * + * @generated + */ + @Override + public boolean eIsSet(int featureID) { + switch (featureID) { + case StylesheetsPackage.THEME__ID: + return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id); + case StylesheetsPackage.THEME__LABEL: + return LABEL_EDEFAULT == null ? label != null : !LABEL_EDEFAULT.equals(label); + case StylesheetsPackage.THEME__ICON: + return ICON_EDEFAULT == null ? icon != null : !ICON_EDEFAULT.equals(icon); + case StylesheetsPackage.THEME__STYLESHEETS: + return stylesheets != null && !stylesheets.isEmpty(); + } + return super.eIsSet(featureID); + } + + /** + * + * + * @generated + */ + @Override + public String toString() { + if (eIsProxy()) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (id: "); + result.append(id); + result.append(", label: "); + result.append(label); + result.append(", icon: "); + result.append(icon); + result.append(')'); + return result.toString(); + } + +} //ThemeImpl diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/WorkspaceThemesImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/WorkspaceThemesImpl.java new file mode 100644 index 00000000000..e4844ff9784 --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/impl/WorkspaceThemesImpl.java @@ -0,0 +1,152 @@ +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl; + +import java.util.Collection; + +import org.eclipse.emf.common.notify.NotificationChain; +import org.eclipse.emf.common.util.EList; + +import org.eclipse.emf.ecore.EClass; + +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.impl.EModelElementImpl; + +import org.eclipse.emf.ecore.util.EObjectContainmentEList; +import org.eclipse.emf.ecore.util.EObjectResolvingEList; + +import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes; + +/** + * + * An implementation of the model object 'Workspace Themes'. + * + *

+ * The following features are implemented: + *

    + *
  • {@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.impl.WorkspaceThemesImpl#getThemes Themes}
  • + *
+ *

+ * + * @generated + */ +public class WorkspaceThemesImpl extends EModelElementImpl implements WorkspaceThemes { + /** + * The cached value of the '{@link #getThemes() Themes}' containment reference list. + * + * + * @see #getThemes() + * @generated + * @ordered + */ + protected EList themes; + + /** + * + * + * @generated + */ + protected WorkspaceThemesImpl() { + super(); + } + + /** + * + * + * @generated + */ + @Override + protected EClass eStaticClass() { + return StylesheetsPackage.Literals.WORKSPACE_THEMES; + } + + /** + * + * + * @generated + */ + public EList getThemes() { + if (themes == null) { + themes = new EObjectContainmentEList(Theme.class, this, StylesheetsPackage.WORKSPACE_THEMES__THEMES); + } + return themes; + } + + /** + * + * + * @generated + */ + @Override + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case StylesheetsPackage.WORKSPACE_THEMES__THEMES: + return ((InternalEList)getThemes()).basicRemove(otherEnd, msgs); + } + return super.eInverseRemove(otherEnd, featureID, msgs); + } + + /** + * + * + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case StylesheetsPackage.WORKSPACE_THEMES__THEMES: + return getThemes(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * + * + * @generated + */ + @SuppressWarnings("unchecked") + @Override + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case StylesheetsPackage.WORKSPACE_THEMES__THEMES: + getThemes().clear(); + getThemes().addAll((Collection)newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * + * + * @generated + */ + @Override + public void eUnset(int featureID) { + switch (featureID) { + case StylesheetsPackage.WORKSPACE_THEMES__THEMES: + getThemes().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * + * + * @generated + */ + @Override + public boolean eIsSet(int featureID) { + switch (featureID) { + case StylesheetsPackage.WORKSPACE_THEMES__THEMES: + return themes != null && !themes.isEmpty(); + } + return super.eIsSet(featureID); + } + +} //WorkspaceThemesImpl diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsAdapterFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsAdapterFactory.java index 0f08df5b9f2..02cbba1d153 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsAdapterFactory.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsAdapterFactory.java @@ -1,194 +1,231 @@ -/** - */ -package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.util; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl; -import org.eclipse.emf.ecore.EModelElement; -import org.eclipse.emf.ecore.EObject; -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; - -/** - * - * The Adapter Factory for the model. - * It provides an adapter createXXX method for each class of the model. - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage - * @generated - */ -public class StylesheetsAdapterFactory extends AdapterFactoryImpl { - /** - * The cached model package. - * - * - * @generated - */ - protected static StylesheetsPackage modelPackage; - - /** - * Creates an instance of the adapter factory. - * - * - * @generated - */ - public StylesheetsAdapterFactory() { - if (modelPackage == null) { - modelPackage = StylesheetsPackage.eINSTANCE; - } - } - - /** - * Returns whether this factory is applicable for the type of the object. - * - * This implementation returns true if the object is either the model's package or is an instance object of the model. - * - * @return whether this factory is applicable for the type of the object. - * @generated - */ - @Override - public boolean isFactoryForType(Object object) { - if (object == modelPackage) { - return true; - } - if (object instanceof EObject) { - return ((EObject)object).eClass().getEPackage() == modelPackage; - } - return false; - } - - /** - * The switch that delegates to the createXXX methods. - * - * - * @generated - */ - protected StylesheetsSwitch modelSwitch = - new StylesheetsSwitch() { - @Override - public Adapter caseModelStyleSheets(ModelStyleSheets object) { - return createModelStyleSheetsAdapter(); - } - @Override - public Adapter caseStyleSheet(StyleSheet object) { - return createStyleSheetAdapter(); - } - @Override - public Adapter caseStyleSheetReference(StyleSheetReference object) { - return createStyleSheetReferenceAdapter(); - } - @Override - public Adapter caseEmbeddedStyleSheet(EmbeddedStyleSheet object) { - return createEmbeddedStyleSheetAdapter(); - } - @Override - public Adapter caseEModelElement(EModelElement object) { - return createEModelElementAdapter(); - } - @Override - public Adapter defaultCase(EObject object) { - return createEObjectAdapter(); - } - }; - - /** - * Creates an adapter for the target. - * - * - * @param target the object to adapt. - * @return the adapter for the target. - * @generated - */ - @Override - public Adapter createAdapter(Notifier target) { - return modelSwitch.doSwitch((EObject)target); - } - - - /** - * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets Model Style Sheets}'. - * - * This default implementation returns null so that we can easily ignore cases; - * it's useful to ignore a case when inheritance will catch all the cases anyway. - * - * @return the new adapter. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets - * @generated - */ - public Adapter createModelStyleSheetsAdapter() { - return null; - } - - /** - * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}'. - * - * This default implementation returns null so that we can easily ignore cases; - * it's useful to ignore a case when inheritance will catch all the cases anyway. - * - * @return the new adapter. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet - * @generated - */ - public Adapter createStyleSheetAdapter() { - return null; - } - - /** - * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference Style Sheet Reference}'. - * - * This default implementation returns null so that we can easily ignore cases; - * it's useful to ignore a case when inheritance will catch all the cases anyway. - * - * @return the new adapter. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference - * @generated - */ - public Adapter createStyleSheetReferenceAdapter() { - return null; - } - - /** - * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet Embedded Style Sheet}'. - * - * This default implementation returns null so that we can easily ignore cases; - * it's useful to ignore a case when inheritance will catch all the cases anyway. - * - * @return the new adapter. - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet - * @generated - */ - public Adapter createEmbeddedStyleSheetAdapter() { - return null; - } - - /** - * Creates a new adapter for an object of class '{@link org.eclipse.emf.ecore.EModelElement EModel Element}'. - * - * This default implementation returns null so that we can easily ignore cases; - * it's useful to ignore a case when inheritance will catch all the cases anyway. - * - * @return the new adapter. - * @see org.eclipse.emf.ecore.EModelElement - * @generated - */ - public Adapter createEModelElementAdapter() { - return null; - } - - /** - * Creates a new adapter for the default case. - * - * This default implementation returns null. - * - * @return the new adapter. - * @generated - */ - public Adapter createEObjectAdapter() { - return null; - } - -} //StylesheetsAdapterFactory +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.util; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl; +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.*; +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; + +/** + * + * The Adapter Factory for the model. + * It provides an adapter createXXX method for each class of the model. + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage + * @generated + */ +public class StylesheetsAdapterFactory extends AdapterFactoryImpl { + /** + * The cached model package. + * + * + * @generated + */ + protected static StylesheetsPackage modelPackage; + + /** + * Creates an instance of the adapter factory. + * + * + * @generated + */ + public StylesheetsAdapterFactory() { + if (modelPackage == null) { + modelPackage = StylesheetsPackage.eINSTANCE; + } + } + + /** + * Returns whether this factory is applicable for the type of the object. + * + * This implementation returns true if the object is either the model's package or is an instance object of the model. + * + * @return whether this factory is applicable for the type of the object. + * @generated + */ + @Override + public boolean isFactoryForType(Object object) { + if (object == modelPackage) { + return true; + } + if (object instanceof EObject) { + return ((EObject)object).eClass().getEPackage() == modelPackage; + } + return false; + } + + /** + * The switch that delegates to the createXXX methods. + * + * + * @generated + */ + protected StylesheetsSwitch modelSwitch = + new StylesheetsSwitch() { + @Override + public Adapter caseModelStyleSheets(ModelStyleSheets object) { + return createModelStyleSheetsAdapter(); + } + @Override + public Adapter caseStyleSheet(StyleSheet object) { + return createStyleSheetAdapter(); + } + @Override + public Adapter caseStyleSheetReference(StyleSheetReference object) { + return createStyleSheetReferenceAdapter(); + } + @Override + public Adapter caseEmbeddedStyleSheet(EmbeddedStyleSheet object) { + return createEmbeddedStyleSheetAdapter(); + } + @Override + public Adapter caseWorkspaceThemes(WorkspaceThemes object) { + return createWorkspaceThemesAdapter(); + } + @Override + public Adapter caseTheme(Theme object) { + return createThemeAdapter(); + } + @Override + public Adapter caseEModelElement(EModelElement object) { + return createEModelElementAdapter(); + } + @Override + public Adapter defaultCase(EObject object) { + return createEObjectAdapter(); + } + }; + + /** + * Creates an adapter for the target. + * + * + * @param target the object to adapt. + * @return the adapter for the target. + * @generated + */ + @Override + public Adapter createAdapter(Notifier target) { + return modelSwitch.doSwitch((EObject)target); + } + + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets Model Style Sheets}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets + * @generated + */ + public Adapter createModelStyleSheetsAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet Style Sheet}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet + * @generated + */ + public Adapter createStyleSheetAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference Style Sheet Reference}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference + * @generated + */ + public Adapter createStyleSheetReferenceAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet Embedded Style Sheet}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet + * @generated + */ + public Adapter createEmbeddedStyleSheetAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes Workspace Themes}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.WorkspaceThemes + * @generated + */ + public Adapter createWorkspaceThemesAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme Theme}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.Theme + * @generated + */ + public Adapter createThemeAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.emf.ecore.EModelElement EModel Element}'. + * + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * + * @return the new adapter. + * @see org.eclipse.emf.ecore.EModelElement + * @generated + */ + public Adapter createEModelElementAdapter() { + return null; + } + + /** + * Creates a new adapter for the default case. + * + * This default implementation returns null. + * + * @return the new adapter. + * @generated + */ + public Adapter createEObjectAdapter() { + return null; + } + +} //StylesheetsAdapterFactory diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsSwitch.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsSwitch.java index de7269f4c43..9af971e27e0 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsSwitch.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.model/src-gen/org/eclipse/papyrus/infra/gmfdiag/css/stylesheets/util/StylesheetsSwitch.java @@ -1,194 +1,238 @@ -/** - */ -package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.util; - -import org.eclipse.emf.ecore.EModelElement; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.util.Switch; -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; - -/** - * - * The Switch for the model's inheritance hierarchy. - * It supports the call {@link #doSwitch(EObject) doSwitch(object)} - * to invoke the caseXXX method for each class of the model, - * starting with the actual class of the object - * and proceeding up the inheritance hierarchy - * until a non-null result is returned, - * which is the result of the switch. - * - * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage - * @generated - */ -public class StylesheetsSwitch extends Switch { - /** - * The cached model package - * - * - * @generated - */ - protected static StylesheetsPackage modelPackage; - - /** - * Creates an instance of the switch. - * - * - * @generated - */ - public StylesheetsSwitch() { - if (modelPackage == null) { - modelPackage = StylesheetsPackage.eINSTANCE; - } - } - - /** - * Checks whether this is a switch for the given package. - * - * - * @parameter ePackage the package in question. - * @return whether this is a switch for the given package. - * @generated - */ - @Override - protected boolean isSwitchFor(EPackage ePackage) { - return ePackage == modelPackage; - } - - /** - * Calls caseXXX for each class of the model until one returns a non null result; it yields that result. - * - * - * @return the first non-null result returned by a caseXXX call. - * @generated - */ - @Override - protected T doSwitch(int classifierID, EObject theEObject) { - switch (classifierID) { - case StylesheetsPackage.MODEL_STYLE_SHEETS: { - ModelStyleSheets modelStyleSheets = (ModelStyleSheets)theEObject; - T result = caseModelStyleSheets(modelStyleSheets); - if (result == null) result = caseEModelElement(modelStyleSheets); - if (result == null) result = defaultCase(theEObject); - return result; - } - case StylesheetsPackage.STYLE_SHEET: { - StyleSheet styleSheet = (StyleSheet)theEObject; - T result = caseStyleSheet(styleSheet); - if (result == null) result = defaultCase(theEObject); - return result; - } - case StylesheetsPackage.STYLE_SHEET_REFERENCE: { - StyleSheetReference styleSheetReference = (StyleSheetReference)theEObject; - T result = caseStyleSheetReference(styleSheetReference); - if (result == null) result = caseStyleSheet(styleSheetReference); - if (result == null) result = defaultCase(theEObject); - return result; - } - case StylesheetsPackage.EMBEDDED_STYLE_SHEET: { - EmbeddedStyleSheet embeddedStyleSheet = (EmbeddedStyleSheet)theEObject; - T result = caseEmbeddedStyleSheet(embeddedStyleSheet); - if (result == null) result = caseStyleSheet(embeddedStyleSheet); - if (result == null) result = defaultCase(theEObject); - return result; - } - default: return defaultCase(theEObject); - } - } - - /** - * Returns the result of interpreting the object as an instance of 'Model Style Sheets'. - * - * This implementation returns null; - * returning a non-null result will terminate the switch. - * - * @param object the target of the switch. - * @return the result of interpreting the object as an instance of 'Model Style Sheets'. - * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) - * @generated - */ - public T caseModelStyleSheets(ModelStyleSheets object) { - return null; - } - - /** - * Returns the result of interpreting the object as an instance of 'Style Sheet'. - * - * This implementation returns null; - * returning a non-null result will terminate the switch. - * - * @param object the target of the switch. - * @return the result of interpreting the object as an instance of 'Style Sheet'. - * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) - * @generated - */ - public T caseStyleSheet(StyleSheet object) { - return null; - } - - /** - * Returns the result of interpreting the object as an instance of 'Style Sheet Reference'. - * - * This implementation returns null; - * returning a non-null result will terminate the switch. - * - * @param object the target of the switch. - * @return the result of interpreting the object as an instance of 'Style Sheet Reference'. - * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) - * @generated - */ - public T caseStyleSheetReference(StyleSheetReference object) { - return null; - } - - /** - * Returns the result of interpreting the object as an instance of 'Embedded Style Sheet'. - * - * This implementation returns null; - * returning a non-null result will terminate the switch. - * - * @param object the target of the switch. - * @return the result of interpreting the object as an instance of 'Embedded Style Sheet'. - * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) - * @generated - */ - public T caseEmbeddedStyleSheet(EmbeddedStyleSheet object) { - return null; - } - - /** - * Returns the result of interpreting the object as an instance of 'EModel Element'. - * - * This implementation returns null; - * returning a non-null result will terminate the switch. - * - * @param object the target of the switch. - * @return the result of interpreting the object as an instance of 'EModel Element'. - * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) - * @generated - */ - public T caseEModelElement(EModelElement object) { - return null; - } - - /** - * Returns the result of interpreting the object as an instance of 'EObject'. - * - * This implementation returns null; - * returning a non-null result will terminate the switch, but this is the last case anyway. - * - * @param object the target of the switch. - * @return the result of interpreting the object as an instance of 'EObject'. - * @see #doSwitch(org.eclipse.emf.ecore.EObject) - * @generated - */ - @Override - public T defaultCase(EObject object) { - return null; - } - -} //StylesheetsSwitch +/** + */ +package org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.util; + +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.util.Switch; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.*; +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; + +/** + * + * The Switch for the model's inheritance hierarchy. + * It supports the call {@link #doSwitch(EObject) doSwitch(object)} + * to invoke the caseXXX method for each class of the model, + * starting with the actual class of the object + * and proceeding up the inheritance hierarchy + * until a non-null result is returned, + * which is the result of the switch. + * + * @see org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage + * @generated + */ +public class StylesheetsSwitch extends Switch { + /** + * The cached model package + * + * + * @generated + */ + protected static StylesheetsPackage modelPackage; + + /** + * Creates an instance of the switch. + * + * + * @generated + */ + public StylesheetsSwitch() { + if (modelPackage == null) { + modelPackage = StylesheetsPackage.eINSTANCE; + } + } + + /** + * Checks whether this is a switch for the given package. + * + * + * @parameter ePackage the package in question. + * @return whether this is a switch for the given package. + * @generated + */ + @Override + protected boolean isSwitchFor(EPackage ePackage) { + return ePackage == modelPackage; + } + + /** + * Calls caseXXX for each class of the model until one returns a non null result; it yields that result. + * + * + * @return the first non-null result returned by a caseXXX call. + * @generated + */ + @Override + protected T doSwitch(int classifierID, EObject theEObject) { + switch (classifierID) { + case StylesheetsPackage.MODEL_STYLE_SHEETS: { + ModelStyleSheets modelStyleSheets = (ModelStyleSheets)theEObject; + T result = caseModelStyleSheets(modelStyleSheets); + if (result == null) result = caseEModelElement(modelStyleSheets); + if (result == null) result = defaultCase(theEObject); + return result; + } + case StylesheetsPackage.STYLE_SHEET: { + StyleSheet styleSheet = (StyleSheet)theEObject; + T result = caseStyleSheet(styleSheet); + if (result == null) result = defaultCase(theEObject); + return result; + } + case StylesheetsPackage.STYLE_SHEET_REFERENCE: { + StyleSheetReference styleSheetReference = (StyleSheetReference)theEObject; + T result = caseStyleSheetReference(styleSheetReference); + if (result == null) result = caseStyleSheet(styleSheetReference); + if (result == null) result = defaultCase(theEObject); + return result; + } + case StylesheetsPackage.EMBEDDED_STYLE_SHEET: { + EmbeddedStyleSheet embeddedStyleSheet = (EmbeddedStyleSheet)theEObject; + T result = caseEmbeddedStyleSheet(embeddedStyleSheet); + if (result == null) result = caseStyleSheet(embeddedStyleSheet); + if (result == null) result = defaultCase(theEObject); + return result; + } + case StylesheetsPackage.WORKSPACE_THEMES: { + WorkspaceThemes workspaceThemes = (WorkspaceThemes)theEObject; + T result = caseWorkspaceThemes(workspaceThemes); + if (result == null) result = caseEModelElement(workspaceThemes); + if (result == null) result = defaultCase(theEObject); + return result; + } + case StylesheetsPackage.THEME: { + Theme theme = (Theme)theEObject; + T result = caseTheme(theme); + if (result == null) result = defaultCase(theEObject); + return result; + } + default: return defaultCase(theEObject); + } + } + + /** + * Returns the result of interpreting the object as an instance of 'Model Style Sheets'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'Model Style Sheets'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseModelStyleSheets(ModelStyleSheets object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'Style Sheet'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'Style Sheet'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseStyleSheet(StyleSheet object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'Style Sheet Reference'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'Style Sheet Reference'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseStyleSheetReference(StyleSheetReference object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'Embedded Style Sheet'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'Embedded Style Sheet'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseEmbeddedStyleSheet(EmbeddedStyleSheet object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'Workspace Themes'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'Workspace Themes'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseWorkspaceThemes(WorkspaceThemes object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'Theme'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'Theme'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseTheme(Theme object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'EModel Element'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'EModel Element'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseEModelElement(EModelElement object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of 'EObject'. + * + * This implementation returns null; + * returning a non-null result will terminate the switch, but this is the last case anyway. + * + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of 'EObject'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) + * @generated + */ + @Override + public T defaultCase(EObject object) { + return null; + } + +} //StylesheetsSwitch diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BrowseFileEditor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BrowseFileEditor.java new file mode 100644 index 00000000000..5bd901b6648 --- /dev/null +++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BrowseFileEditor.java @@ -0,0 +1,408 @@ +/***************************************************************************** + * 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.widgets.editors; + + + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; +import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.infra.widgets.messages.Messages; +import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider; +import org.eclipse.papyrus.infra.widgets.util.FileUtil; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.FileDialog; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; + + +/** + * Specific String editor to select a file with unique button. + * + * @author gpascual + * + */ +public class BrowseFileEditor extends StringEditor { + + /** Unique button with associated menu to choice where file will be selected. */ + private Button button = null; + + /** List of accepted file extensions. */ + private List filterExtensions = new ArrayList(); + + /** List of accepted names. */ + private List filterNames = new ArrayList(); + + /** Attribute to allow file from workspace. */ + private boolean allowWorkspace = true; + + /** Attribute to allow file from file system. */ + private boolean allowFileSystem = true; + + /** Attribute for writing rights. */ + private boolean readOnly = false; + + /** Menu of file system. */ + private MenuItem fileSystemMenuItem = null; + + /** Menu of workspace. */ + private MenuItem workspaceMenuItem = null; + + /** + * Default constructor. + * + * @param parent + * the parent + * @param style + * the style + */ + public BrowseFileEditor(Composite parent, int style) { + super(parent, style); + ((GridLayout)getLayout()).numColumns++; + button = factory.createButton(this, Messages.StringFileSelector_Browse, SWT.PUSH); + button.setLayoutData(new GridData()); + + + final Menu browseMenu = createButtonMenu(); + + + + // Display menu when user select button + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + browseMenu.setVisible(true); + } + }); + + } + + + /** + * Creates the button menu. + * + * @return the menu + */ + private Menu createButtonMenu() { + final Menu browseMenu = new Menu(button); + + // Add file system menu + fileSystemMenuItem = new MenuItem(browseMenu, SWT.NONE); + fileSystemMenuItem.setText("File system"); + fileSystemMenuItem.addSelectionListener(new SelectionAdapter() { + + + + @Override + public void widgetSelected(SelectionEvent e) { + File file = getFile(text.getText()); + + FileDialog dialog = new FileDialog(getShell()); + if(labelText != null) { + dialog.setText(labelText); + } + dialog.setFileName(file.getAbsolutePath()); + dialog.setFilterExtensions(filterExtensions.toArray(new String[filterExtensions.size()])); + dialog.setFilterNames(filterNames.toArray(new String[filterNames.size()])); + String result = dialog.open(); + if(result == null) { //Cancel + return; + } + setResult(result); + } + }); + + // Add workspace menu + workspaceMenuItem = new MenuItem(browseMenu, SWT.NONE); + workspaceMenuItem.setText("Workspace"); + workspaceMenuItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + LabelProviderService labelProviderService = new LabelProviderServiceImpl(); + try { + labelProviderService.startService(); + } catch (ServiceException ex) { + Activator.log.error(ex); + } + + ILabelProvider labelProvider = labelProviderService.getLabelProvider(); + + IFile currentFile = getIFile(text.getText()); + + TreeSelectorDialog dialog = new TreeSelectorDialog(getShell()); + if(labelText != null) { + dialog.setTitle(labelText); + } + + WorkspaceContentProvider contentProvider = new WorkspaceContentProvider(); + + if(!(filterExtensions.isEmpty() || filterNames.isEmpty())) { + //The filters have been defined + contentProvider.setExtensionFilters(new LinkedHashMap()); //Reset the default filters + + //Use our own filters + for(int i = 0; i < Math.min(filterNames.size(), filterExtensions.size()); i++) { + contentProvider.addExtensionFilter(filterExtensions.get(i), filterNames.get(i)); + } + } + + dialog.setContentProvider(contentProvider); + dialog.setLabelProvider(labelProvider); + + + if(currentFile != null && currentFile.exists()) { + dialog.setInitialSelections(new IFile[]{ currentFile }); + } + + int code = dialog.open(); + if(code == Window.OK) { + Object[] result = dialog.getResult(); + if(result.length > 0) { + Object file = result[0]; + if(file instanceof IFile) { + setResult((IFile)file); + } + } + } + } + }); + + return browseMenu; + } + + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(IFile file) { + text.setText(file.getFullPath().toString()); + notifyChange(); + } + + /** + * Sets the result. + * + * @param file + * the new result + */ + protected void setResult(File file) { + text.setText(file.getAbsolutePath()); + notifyChange(); + } + + /** + * Sets the result. + * + * @param path + * the new result + */ + protected void setResult(String path) { + text.setText(path); + notifyChange(); + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the i file + */ + protected IFile getIFile(String path) { + return FileUtil.getIFile(path); + } + + /** + * Gets the file. + * + * @param path + * the path + * @return the file + */ + protected File getFile(String path) { + return FileUtil.getFile(path); + } + + /** + * Sets the filters. + * + * @param filterExtensions + * the filter extensions + * @param filterNames + * the filter names + */ + public void setFilters(String[] filterExtensions, String[] filterNames) { + if(filterExtensions.length != filterNames.length) { + //This is a simple warning. Only valid filters will be retained. + Activator.log.warn("FilterExtensions and FilterNames do not match"); + } + + setFilterNames(getFilterLabels(filterNames, filterExtensions)); + setFilterExtensions(filterExtensions); + } + + /** + * Gets the filter labels. + * + * @param filterNames + * the filter names + * @param filterExtensions + * the filter extensions + * @return the filter labels + */ + protected String[] getFilterLabels(String[] filterNames, String[] filterExtensions) { + int size = Math.min(filterNames.length, filterExtensions.length); + String[] filters = new String[size]; + for(int i = 0; i < size; i++) { + filters[i] = filterNames[i] + " (" + filterExtensions[i] + ")"; + } + return filters; + } + + /** + * Sets the filter extensions. + * + * @param filterExtensions + * the new filter extensions + */ + public void setFilterExtensions(String[] filterExtensions) { + this.filterExtensions = Arrays.asList(filterExtensions); + } + + /** + * Sets the filter names. + * + * @param filterNames + * the new filter names + */ + public void setFilterNames(String[] filterNames) { + this.filterNames = Arrays.asList(filterNames); + } + + /** + * Adds the filtered extension. + * + * @param filteredExtension + * the filtered extension + * @param filterName + * the filter name + */ + public void addFilteredExtension(String filteredExtension, String filterName) { + if(filteredExtension != null) { + if(filterName == null) { + filterName = filteredExtension; + } + + filterExtensions.add(filteredExtension); + filterNames.add(filterName); + } + } + + /** + * @see org.eclipse.papyrus.infra.widgets.editors.StringEditor#getEditableType() + * + * @return + */ + + @Override + public Object getEditableType() { + return String.class; + } + + /** + * @see org.eclipse.papyrus.infra.widgets.editors.StringEditor#setReadOnly(boolean) + * + * @param readOnly + */ + + @Override + public void setReadOnly(boolean readOnly) { + super.setReadOnly(readOnly); + this.readOnly = readOnly; + updateButtons(); + } + + /** + * Sets the allow workspace. + * + * @param allowWorkspace + * the new allow workspace + */ + public void setAllowWorkspace(boolean allowWorkspace) { + this.allowWorkspace = allowWorkspace; + updateButtons(); + } + + /** + * Sets the allow file system. + * + * @param allowFileSystem + * the new allow file system + */ + public void setAllowFileSystem(boolean allowFileSystem) { + + this.allowFileSystem = allowFileSystem; + updateButtons(); + } + + /** + * Sets the button label. + * + * @param label + * the new button label + */ + public void setButtonLabel(String label) { + button.setText(label); + } + + /** + * Gets the button label. + * + * @return the button label + */ + public String getButtonLabel() { + return button.getText(); + } + + /** + * Update buttons. + */ + private void updateButtons() { + boolean enableWorkspace = !readOnly && allowWorkspace; + boolean enableFileSystem = !readOnly && allowFileSystem; + //((GridData)browseWorkspace.getLayoutData()).exclude = !allowWorkspace; + //((GridData)browse.getLayoutData()).exclude = !allowFileSystem; + fileSystemMenuItem.setEnabled(enableWorkspace); + workspaceMenuItem.setEnabled(enableFileSystem); + } +} diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/model/Environment.xmi b/plugins/views/properties/org.eclipse.papyrus.views.properties/model/Environment.xmi index b311164df1a..6bf05b56904 100644 --- a/plugins/views/properties/org.eclipse.papyrus.views.properties/model/Environment.xmi +++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/model/Environment.xmi @@ -1,55 +1,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/widgets/BrowseFilePropertyEditor.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/widgets/BrowseFilePropertyEditor.java new file mode 100644 index 00000000000..a2d0f078be4 --- /dev/null +++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/widgets/BrowseFilePropertyEditor.java @@ -0,0 +1,175 @@ +/***************************************************************************** + * 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.views.properties.widgets; + +import org.eclipse.papyrus.infra.widgets.editors.BrowseFileEditor; +import org.eclipse.swt.widgets.Composite; + + +/** + * Property editor for attribute that need a file selection. + * Its display have unique button with an associated menu to choice where file comes frome. + */ +public class BrowseFilePropertyEditor extends AbstractPropertyEditor { + + /** The browse file editor. */ + private BrowseFileEditor browseFileEditor = null; + + /** The filtered extensions This should be a 1-1 mapping with {@link #filterNames}. */ + protected String[] filterExtensions = null; + + /** + * The name of the filters. + * This should be a 1-1 mapping with {@link #filterExtensions} + */ + protected String[] filterNames = null; + + /** Enables the "browse workspace" feature. */ + protected boolean allowWorkspace = true; + + /** Enables the "browse file system" feature. */ + protected boolean allowFileSystem = true; + + /** + * Instantiates a new browse file property editor. + * + * @param parent + * the parent + * @param style + * the style + */ + public BrowseFilePropertyEditor(Composite parent, int style) { + browseFileEditor = createBrowseFileEditor(parent, style); + super.setEditor(browseFileEditor); + } + + /** + * Set label to browse button. + * + * @param buttonLabel + * Label to set + */ + public void setButtonLabel(String buttonLabel) { + browseFileEditor.setButtonLabel(buttonLabel); + } + + + /** + * @return Label of browse button + */ + public String getButtonLabel() { + return browseFileEditor.getButtonLabel(); + } + + /** + * Creates the browse file editor. + * + * @param parent + * the parent + * @param style + * the style + * @return the browse file editor + */ + private BrowseFileEditor createBrowseFileEditor(Composite parent, int style) { + + return new BrowseFileEditor(parent, style); + } + + /** + * Sets the filter extensions. + * + * @param filterExtensions + * the new filter extensions + */ + public void setFilterExtensions(String[] filterExtensions) { + this.filterExtensions = filterExtensions; + checkFilters(); + } + + /** + * Gets the filter extensions. + * + * @return the filter extensions + */ + public String[] getFilterExtensions() { + return this.filterExtensions; + } + + /** + * Sets the filter names. + * + * @param filterNames + * the new filter names + */ + public void setFilterNames(String[] filterNames) { + this.filterNames = filterNames; + checkFilters(); + } + + /** + * Gets the filter names. + * + * @return the filter names + */ + public String[] getFilterNames() { + return this.filterNames; + } + + /** + * Checks if the filters are valid. + */ + protected void checkFilters() { + if(filterExtensions != null && filterNames != null) { + browseFileEditor.setFilters(filterExtensions, filterNames); + } + } + + /** + * Indicates whether the editor should allow browsing the workspace or not. + * + * @param allowWorkspace + * the new allow workspace + */ + public void setAllowWorkspace(boolean allowWorkspace) { + this.allowWorkspace = allowWorkspace; + browseFileEditor.setAllowWorkspace(allowWorkspace); + } + + /** + * Gets the allow workspace. + * + * @return true if the editor can browse the workspace + */ + public boolean getAllowWorkspace() { + return allowWorkspace; + } + + /** + * Indicates whether the editor should allow browsing the file system or not. + * + * @param allowFileSystem + * the new allow file system + */ + public void setAllowFileSystem(boolean allowFileSystem) { + this.allowFileSystem = allowFileSystem; + browseFileEditor.setAllowFileSystem(allowFileSystem); + } + + /** + * Gets the allow file system. + * + * @return true if the editor can browse the fileSystem + */ + public boolean getAllowFileSystem() { + return allowFileSystem; + } +} -- cgit v1.2.3