diff options
Diffstat (limited to 'extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences')
40 files changed, 3588 insertions, 0 deletions
diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.classpath b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.classpath new file mode 100755 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.gitignore b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.gitignore new file mode 100755 index 00000000000..ae3c1726048 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.options b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.options new file mode 100755 index 00000000000..3d16767c9da --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.options @@ -0,0 +1,3 @@ +# Tracing options for the org.eclipse.papyrus.infra.propertylifecycle.preferences plug-in
+org.eclipse.papyrus.infra.propertylifecycle.preferences/debug=true
+org.eclipse.papyrus.infra.propertylifecycle.preferences/debug/lifecyclepreferences=true
diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.project b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.project new file mode 100755 index 00000000000..69c889ad21c --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.propertylifecycle.preferences</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.settings/org.eclipse.jdt.core.prefs b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 00000000000..0c68a61dca8 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/META-INF/MANIFEST.MF b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/META-INF/MANIFEST.MF new file mode 100755 index 00000000000..a12006b22c6 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: PropertyLifecyclePreferences +Bundle-SymbolicName: org.eclipse.papyrus.propertylifecycle.preferences;singleton:=true +Bundle-Version: 0.0.1.qualifier +Bundle-Activator: org.eclipse.papyrus.propertylifecycle.preferences.Activator +Require-Bundle: org.eclipse.ui;bundle-version="3.107.0", + org.eclipse.core.runtime;bundle-version="3.12.0", + org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0", + org.eclipse.papyrus.propertylifecycle.model;bundle-version="0.0.1", + org.eclipse.papyrus.propertylifecycle.model.editor;bundle-version="0.0.1" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.papyrus.propertylifecycle.preferences.utils diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/about.html b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/about.html new file mode 100755 index 00000000000..d35d5aed64c --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 5, 2007</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html> diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/build.properties b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/build.properties new file mode 100755 index 00000000000..34d2e4d2dad --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/menu/removeStrategyModel_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/menu/removeStrategyModel_16x16.gif Binary files differnew file mode 100755 index 00000000000..8995a3057b5 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/menu/removeStrategyModel_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/menu/removeStrategy_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/menu/removeStrategy_16x16.gif Binary files differnew file mode 100755 index 00000000000..84f0315f2bd --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/menu/removeStrategy_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_left_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_left_16x16.gif Binary files differnew file mode 100755 index 00000000000..4fb41501036 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_left_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_left_double_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_left_double_16x16.gif Binary files differnew file mode 100755 index 00000000000..336b55cf08e --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_left_double_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_right_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_right_16x16.gif Binary files differnew file mode 100755 index 00000000000..19567890aa8 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_right_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_right_double_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_right_double_16x16.gif Binary files differnew file mode 100755 index 00000000000..c02db2c9df4 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/arrow_right_double_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/synced_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/synced_16x16.gif Binary files differnew file mode 100755 index 00000000000..870934b6934 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/navigation/synced_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/tableViewer/checked_12x12.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/tableViewer/checked_12x12.gif Binary files differnew file mode 100755 index 00000000000..a2669a8ea32 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/tableViewer/checked_12x12.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/tableViewer/unchecked_12x12.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/tableViewer/unchecked_12x12.gif Binary files differnew file mode 100755 index 00000000000..49094593b40 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/tableViewer/unchecked_12x12.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/container_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/container_16x16.gif Binary files differnew file mode 100755 index 00000000000..7ccc6a70317 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/container_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/property_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/property_16x16.gif Binary files differnew file mode 100755 index 00000000000..d11c996e570 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/property_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/resource_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/resource_16x16.gif Binary files differnew file mode 100755 index 00000000000..2e4de3d12a7 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/resource_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/strategySet_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/strategySet_16x16.gif Binary files differnew file mode 100755 index 00000000000..131c28da405 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/strategySet_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/strategy_16x16.gif b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/strategy_16x16.gif Binary files differnew file mode 100755 index 00000000000..51e703b1b9c --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/icons/treeViewer/strategy_16x16.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/plugin.xml b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/plugin.xml new file mode 100755 index 00000000000..1c36b4ad180 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/plugin.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.ui.preferencePages"> + <page + category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory" + class="org.eclipse.papyrus.propertylifecycle.preferences.pages.PropertyLifecyclePreferencesPage" + id="org.eclipse.papyrus.infra.propertylifecycle.preferences.pages.PropertyLifecyclePage" + name="Property Lifecycle Page"> + </page> + </extension> + +</plugin> diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/pom.xml b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/pom.xml new file mode 100755 index 00000000000..dd53fbc2439 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/pom.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>org.eclipse.papyrus.infra.propertylifecycle.preferences</artifactId> + <version>0.0.1.qualifier</version> + <groupId>org.eclipse.papyrus</groupId> + <packaging>eclipse-plugin</packaging> + <parent> + <groupId>org.eclipse.papyrus</groupId> + <artifactId>org.eclipse.papyrus.infra.propertylifecycle</artifactId> + <version>0.0.1.qualifier</version> + <relativePath>../org.eclipse.papyrus.infra.propertylifecycle/pom.xml</relativePath> + </parent> +</project> diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/Activator.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/Activator.java new file mode 100755 index 00000000000..75258b7f4cf --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/Activator.java @@ -0,0 +1,120 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + * + */ +public class Activator extends AbstractUIPlugin { + + /** The plug-in ID */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.propertylifecycle.preferences"; //$NON-NLS-1$ + + /** The shared instance */ + private static Activator plugin; + + /** Logging helper */ + public static LogHelper log; + + /** The tag to identify the trace when activating the messages in the .options file */ + public static String STRATEGY_PREFERENCES_TRACE = "lifecyclepreferences"; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + log = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Get the image from its path in the current plugin + * + * @param path + * @return + * The {@link #org.eclipse.swt.graphics.Image image} + */ + public Image getImage(String path) { + return getImage(PLUGIN_ID, path); + } + + /** + * Get the image from its path in the specified plugin + * + * @param pluginId + * @param path + * @return + * The {@link #org.eclipse.swt.graphics.Image image} + */ + public Image getImage(String pluginId, String path) { + final ImageRegistry registry = getImageRegistry(); + String key = pluginId + "/" + path; //$NON-NLS-1$ + Image image = registry.get(key); + if (image == null) { + registry.put(key, AbstractUIPlugin.imageDescriptorFromPlugin(pluginId, path)); + image = registry.get(key); + } + return image; + } + + /** + * Returns an image descriptor for the image file at the given plug-in relative path. + * + * @param path + * @return the image descriptor + */ + public ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/messages/Messages.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/messages/Messages.java new file mode 100755 index 00000000000..25b22283fd6 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/messages/Messages.java @@ -0,0 +1,129 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.messages; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages Class + * + */ +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.propertylifecycle.preferences.messages.messages"; //$NON-NLS-1$ + + // Preference page + public static String PropertyLifecycle_PreferencePage_Title; + + public static String PropertyLifecycle_PreferencePage_Description; + + public static String Choose_Configuration; + + // ControlsComposite + public static String PropertyLifecycleStrategies; + + public static String Sync_Label; + + public static String Sync_IconPath; + + public static String Add_Label; + + public static String Add_IconPath; + + public static String Remove_Label; + + public static String Remove_IconPath; + + public static String RemoveAll_Label; + + public static String RemoveAll_IconPath; + + public static String AddAll_Label; + + public static String AddAll_IconPath; + + // TreeViewer + public static String Resource_IconPath; + + public static String StrategySet_IconPath; + + public static String Strategy_IconPath; + + public static String Property_IconPath; + + public static String ElementContainer_IconPath; + + // StrategiesComposite + public static String StrategyElement_Label; + + public static String ElementProperty_Label; + + public static String ElementContainer_Label; + + // SystemSelectionDialog + public static String SystemSelectionDialog_Title; + + public static String SystemSaveDialog_Title; + + // Menu + public static String AddStrategy_Label; + + public static String AddStrategy_IconPath; + + public static String RemoveStrategy_Label; + + public static String RemoveStrategy_IconPath; + + public static String RemoveStrategyModel_Label; + + public static String RemoveStrategyModel_IconPath; + + public static String RemoveAllStrategies_Label; + + public static String RemoveAllStrategies_IconPath; + + // Preferences + public static String BasicBrowsedModels_Node; + + public static String BasicSelectedStrategies_Node; + + public static String AdvancedBrowsedModels_Node; + + public static String AdvancedSelectedStrategies_Node; + + // Models buttons + public static String SaveButton_Label; + + public static String BrowseButton_Label; + + public static String CustomModel_DefaultName; + + // TableViewer + public static String SelectAllButton_Label; + + public static String DeselectAllButton_Label; + + public static String Checked_IconPath; + + public static String Unchecked_IconPath; + + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/messages/messages.properties b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/messages/messages.properties new file mode 100755 index 00000000000..1485d31dabc --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/messages/messages.properties @@ -0,0 +1,52 @@ +PropertyLifecycle_PreferencePage_Title=Papyrus Property LifeCycle Strategies +PropertyLifecycle_PreferencePage_Description=Select one or more strategies to be applied on subsequent element creations: +Choose_Configuration=Choose the needed Strategy Configuration: + +PropertyLifecycleStrategies=PropertyLifeCycleStrategies + +Sync_Label=Link with Registered Models +Sync_IconPath=/icons/navigation/synced_16x16.gif +Add_Label=addButton +Add_IconPath=/icons/navigation/arrow_right_16x16.gif +Remove_Label=removeButton +Remove_IconPath=/icons/navigation/arrow_left_16x16.gif +AddAll_Label=addAllButton +AddAll_IconPath=/icons/navigation/arrow_right_double_16x16.gif +RemoveAll_Label=removeAllButton +RemoveAll_IconPath=/icons/navigation/arrow_left_double_16x16.gif + +Resource_IconPath=/icons/treeViewer/resource_16x16.gif +StrategySet_IconPath=/icons/treeViewer/strategySet_16x16.gif +Strategy_IconPath=/icons/treeViewer/Strategy_16x16.gif +Property_IconPath=/icons/treeViewer/property_16x16.gif +ElementContainer_IconPath=/icons/treeViewer/container_16x16.gif + +StrategyElement_Label=Element base type: +ElementProperty_Label=FeatureLabel: +ElementContainer_Label=Container base type: + +SystemSelectionDialog_Title=Select the models to load +SystemSaveDialog_Title=Select the directory for the new model + +AddStrategy_Label=Add selected Strategies +AddStrategy_IconPath=/icons/menu/addStrategy_16x16.gif +RemoveStrategy_Label=Remove selected strategies +RemoveStrategy_IconPath=/icons/menu/removeStrategy_16x16.gif +RemoveStrategyModel_Label=Remove selected Model +RemoveStrategyModel_IconPath=/icons/menu/removeStrategyModel_16x16.gif +RemoveAllStrategies_Label=Remove All strategies +RemoveAllStrategies_IconPath=/icons/menu/removeAll_16x16.gif + +BasicBrowsedModels_Node=basicBrowsedModelsURI +BasicSelectedStrategies_Node=basicSelectedStrategies +AdvancedBrowsedModels_Node=advancedBrowsedModelsURI +AdvancedSelectedStrategies_Node=advancedSelectedStrategies + +SaveButton_Label=Save Strategies +BrowseButton_Label=Browse Models +CustomModel_DefaultName=CustomModel + +SelectAllButton_Label=Select All +DeselectAllButton_Label= Deselect All +Checked_IconPath=/icons/tableViewer/checked_12x12.gif +Unchecked_IconPath=/icons/tableViewer/unchecked_12x12.gif diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTab.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTab.java new file mode 100755 index 00000000000..df03e5caaae --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTab.java @@ -0,0 +1,390 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.pages; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.BrowseButton; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.SaveButton; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +/** + * Handle the creation of the advanced Tab in the preference page + * + */ +public class AdvancedTab implements SelectionListener { + + /** Composite containing the left viewer representing the resources and strategies available for selection */ + protected AdvancedTabLeftViewerComposite leftViewerComposite; + + /** Composite containing the right viewer representing the current selection of strategies */ + protected AdvancedTabRightViewerComposite rightViewerComposite; + + /** Composite containing the middle buttons used to add, delete or sync the strategies between both viewers */ + private Composite controlComposite; + + /** Button used to synchronize the selection between both viewers */ + private Button syncButton; + + /** Button used to add a new set of strategies to the selected ones */ + private Button addButton; + + /** Button used to remove the selection from the selected strategies */ + private Button removeButton; + + /** Button used to add all the strategies from the left viewer to the right */ + private Button addAllButton; + + /** Button used to remove all the strategies from the right viewer */ + private Button removeAllButton; + + /** the selection in the viewer */ + private List<Object> viewerSelection = new LinkedList<>(); + + /** the IDs of the selected strategies to filter during synchronization */ + private List<String> viewerSelectionIDs = new LinkedList<>(); + + /** List containing the strategies found on both viewers */ + private List<StrategyElement> twinViewerSelection = new LinkedList<>(); + + + /** + * + * Constructor. + * + * @param parent + * The containing Composite + * @param style + */ + public AdvancedTab(CTabFolder parent, int style) { + CTabItem advancedTabItem = new CTabItem(parent, SWT.NONE); + advancedTabItem.setText("Advanced Selection"); + + GridLayout compositeLayout = new GridLayout(3, false); + Composite advancedTabComposite = new Composite(parent, style); + advancedTabComposite.setLayout(compositeLayout); + advancedTabComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 3)); + advancedTabItem.setControl(advancedTabComposite); + + createStrategiesComposite(advancedTabComposite); + createControlsComposite(advancedTabComposite); + createSelectionComposite(advancedTabComposite); + + new BrowseButton(advancedTabComposite, leftViewerComposite.getViewer()); + new SaveButton(advancedTabComposite, getRightViewer()); + } + + + /** + * Creates the rightViewer containing all the possible choices + * + * @param parent + * this + */ + protected void createStrategiesComposite(Composite parent) { + leftViewerComposite = new AdvancedTabLeftViewerComposite(parent, SWT.NONE); + ((GridData) leftViewerComposite.getLayoutData()).verticalSpan = 2; + ((GridData) leftViewerComposite.getLayoutData()).horizontalSpan = 1; + } + + /** + * The selection buttons' composite + * + * @param parent + * this + */ + protected void createControlsComposite(Composite parent) { + controlComposite = new Composite(parent, SWT.NONE); + controlComposite.setLayout(new GridLayout(1, true)); + GridData controlLayoutData = new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 3); + controlComposite.setLayoutData(controlLayoutData); + + syncButton = new Button(controlComposite, SWT.TOGGLE); + syncButton.setImage(Activator.getDefault().getImage(Messages.Sync_IconPath)); + syncButton.addSelectionListener(this); + syncButton.setToolTipText(Messages.Sync_Label); + + addButton = new Button(controlComposite, SWT.PUSH); + addButton.setImage(Activator.getDefault().getImage(Messages.Add_IconPath)); + addButton.addSelectionListener(this); + addButton.setToolTipText(Messages.Add_Label); + + removeButton = new Button(controlComposite, SWT.PUSH); + removeButton.setImage(Activator.getDefault().getImage(Messages.Remove_IconPath)); + removeButton.addSelectionListener(this); + removeButton.setToolTipText(Messages.Remove_Label); + + addAllButton = new Button(controlComposite, SWT.PUSH); + addAllButton.setImage(Activator.getDefault().getImage(Messages.AddAll_IconPath)); + addAllButton.addSelectionListener(this); + addAllButton.setToolTipText(Messages.AddAll_Label); + + removeAllButton = new Button(controlComposite, SWT.PUSH); + removeAllButton.setImage(Activator.getDefault().getImage(Messages.RemoveAll_IconPath)); + removeAllButton.addSelectionListener(this); + removeAllButton.setToolTipText(Messages.RemoveAll_Label); + } + + /** + * Creates the left viewer containing the selected options + * + * @param parent + * this + */ + protected void createSelectionComposite(Composite parent) { + rightViewerComposite = new AdvancedTabRightViewerComposite(parent, SWT.NONE); + ((GridData) rightViewerComposite.getLayoutData()).horizontalSpan = 1; + ((GridData) rightViewerComposite.getLayoutData()).verticalSpan = 2; + } + + + /** + * Get the left Viewer + * + * @return + */ + public TreeViewer getLeftViewer() { + return leftViewerComposite.getViewer(); + } + + /** + * Get the right Viewer + * + * @return + */ + public TreeViewer getRightViewer() { + return rightViewerComposite.getViewer(); + } + + /** + * Method forwarding the selected configurations to the right viewer + * + * @param advancedTabStrategies + */ + public void addStrategies(Collection<StrategyElement> advancedTabStrategies) { + rightViewerComposite.addStrategies(advancedTabStrategies); + } + + /** + * Method removing all the right viewer strategies + */ + public void removeAllSelectionCompositeStrategies() { + rightViewerComposite.removeAllStrategies(); + } + + /** + * Method forwarding the resources to populate the left viewer + * + * @param resourceSet + */ + public void setRegisteredCompositeInput(ResourceSet resourceSet) { + leftViewerComposite.getViewer().setInput(resourceSet); + } + + /** + * Get the addresses of the resources containing the selected strategies + * + * @return + */ + public Collection<String> getAdvancedParentModels() { + return rightViewerComposite.getParentModels(); + } + + /** + * Get the strategies selected in the right viewer + * + * @return + */ + public Collection<StrategyElement> getAdvancedStrategies() { + return rightViewerComposite.getViewerStrategies(); + } + + /** + * Handles the buttons' behavior + * + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + * + * @param e + * The selection event + */ + @Override + public void widgetSelected(SelectionEvent e) { + if (e.widget == addButton) { + addAction(); + } else if (e.widget == removeButton) { + removeAction(); + } else if (e.widget == addAllButton) { + addAllAction(); + } else if (e.widget == removeAllButton) { + removeAllAction(); + } else if (e.widget == syncButton) { + syncAction(); + } + } + + /** + * Add the selected preference(s) to the Viewer + */ + private void addAction() { + rightViewerComposite.addStrategies(leftViewerComposite.getStrategiesSelection()); + } + + /** + * Add all the possible preferences to the Viewer + */ + private void addAllAction() { + rightViewerComposite.addStrategies(leftViewerComposite.getViewerInput()); + } + + /** + * Remove the selected preference(s) from the Viewer + */ + private void removeAction() { + rightViewerComposite.removeSelectedStrategies(); + } + + /** + * Remove all the selected preferences from the Viewer + */ + private void removeAllAction() { + rightViewerComposite.removeAllStrategies(); + } + + /** + * Method handling the synchronization between the left and right viewer + * + * @param selectionViewer + * @param twinViewer + * @param twinStrategies + */ + private void doSync(TreeViewer selectionViewer, TreeViewer twinViewer, Collection<StrategyElement> twinStrategies) { + viewerSelection.clear(); + viewerSelectionIDs.clear(); + twinViewerSelection.clear(); + viewerSelection.addAll(selectionViewer.getStructuredSelection().toList()); + + if (viewerSelection.size() < 0) { + return; + } + + for (Object object : viewerSelection) { + if (!(object instanceof StrategyElement)) { + continue; + } + StrategyElement strategy = (StrategyElement) object; + viewerSelectionIDs.add(strategy.getId()); + } + + for (StrategyElement strategy : twinStrategies) { + if (viewerSelectionIDs.contains(strategy.getId())) { + twinViewerSelection.add(strategy); + } + } + + twinViewer.setSelection(new StructuredSelection(twinViewerSelection), true); + } + + /** Listener used to sync to the right to the left viewer */ + ISelectionChangedListener syncToRegisteredListener = new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + doSync(rightViewerComposite.getViewer(), leftViewerComposite.getViewer(), leftViewerComposite.getViewerStrategies()); + } + }; + + /** Listener used to sync the left to the right viewer */ + ISelectionChangedListener syncToSelectedListener = new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + doSync(leftViewerComposite.getViewer(), rightViewerComposite.getViewer(), rightViewerComposite.getViewerStrategies()); + } + }; + + /** @see org.eclipse.swt.events.FocusListener used to detect the synchronization and update the viewer accordingly */ + FocusListener selectedFocusListener = new FocusListener() { + + @Override + public void focusGained(FocusEvent e) { + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, "selectedViewerFocus gained"); + if (syncButton.getSelection()) { + rightViewerComposite.getViewer().addSelectionChangedListener(syncToRegisteredListener); + } + } + + @Override + public void focusLost(FocusEvent e) { + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, "selectedViewerFocus lost"); + rightViewerComposite.treeViewer.removeSelectionChangedListener(syncToRegisteredListener); + } + }; + + /** @see org.eclipse.swt.events.FocusListener used to detect the synchronization and update the viewer accordingly */ + FocusListener registeredFocusListener = new FocusListener() { + + @Override + public void focusGained(FocusEvent e) { + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, "registeredViewerFocus gained"); + if (syncButton.getSelection()) { + leftViewerComposite.getViewer().addSelectionChangedListener(syncToSelectedListener); + } + } + + @Override + public void focusLost(FocusEvent e) { + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, "registeredViewerFocus lost"); + leftViewerComposite.getViewer().removeSelectionChangedListener(syncToSelectedListener); + } + }; + + /** + * Method enabling the listeners used to detect the selected strategies on the viewers + */ + private void syncAction() { + if (syncButton.getSelection()) { + rightViewerComposite.getViewer().getTree().addFocusListener(selectedFocusListener); + leftViewerComposite.getViewer().getTree().addFocusListener(registeredFocusListener); + } else { + rightViewerComposite.getViewer().getTree().removeFocusListener(selectedFocusListener); + leftViewerComposite.getViewer().getTree().removeFocusListener(registeredFocusListener); + } + } + + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // nothing + } +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTabLeftViewerComposite.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTabLeftViewerComposite.java new file mode 100755 index 00000000000..07529e62564 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTabLeftViewerComposite.java @@ -0,0 +1,258 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.pages; + +import java.util.Collection; +import java.util.LinkedList; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.AdvancedTabLabelProvider; +import org.eclipse.papyrus.propertylifecycle.presentation.PropertylifecycleEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +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.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.dialogs.FilteredTree; +import org.eclipse.ui.dialogs.PatternFilter; + + +/** + * Class handling the left viewer of the advanced Tab + * + */ +public class AdvancedTabLeftViewerComposite extends Composite { + + /** Factory used to get the information on the elements to populate the viewer */ + protected AdapterFactory adapterFactory; + + /** the viewer showing the available strategies */ + protected FilteredTree filteredViewer; + + /** Listener used to detect a different selection */ + protected ISelectionChangedListener selectionChangedListener; + + /** Listener used to identify the selected strategies */ + protected ISelection viewerSelection = StructuredSelection.EMPTY; + + /** Filter used to... filter the displayed strategies */ + protected PatternFilter patternFilter; + + // protected String elementFilter; + + + /** + * + * Constructor. + * + * @param parent + * The parent composite + * @param style + */ + public AdvancedTabLeftViewerComposite(Composite parent, int style) { + super(parent, style); + this.setLayout(new GridLayout(1, true)); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + PropertylifecycleEditor contentEditor = new PropertylifecycleEditor(); + adapterFactory = contentEditor.getAdapterFactory(); + patternFilter = new PatternFilter(); + patternFilter.setIncludeLeadingWildcard(true); + + initStrategySelectionListener(); + createViewer(this); + } + + /** + * Create the viewer + * + * @param parent + * This composite + */ + protected void createViewer(Composite parent) { + filteredViewer = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true); + getViewer().setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); + getViewer().setLabelProvider(new AdvancedTabLabelProvider(adapterFactory)); + + getViewer().addSelectionChangedListener(selectionChangedListener); + + // Used to filter the elements in order to display the popup menu + Tree tree = getViewer().getTree(); + final Menu rightClickMenu = new Menu(tree); + tree.setMenu(rightClickMenu); + rightClickMenu.addMenuListener(new MenuAdapter() { + + @Override + public void menuShown(MenuEvent e) { + MenuItem[] items = rightClickMenu.getItems(); + for (int i = 0; i < items.length; i++) { + items[i].dispose(); + } + + if ((((StructuredSelection) viewerSelection).getFirstElement() instanceof Resource)) { + strategySetMenu(rightClickMenu); + } + } + }); + + } + + /** + * Create the menu item used to remove the selected model + * + * @param associatedMenu + */ + private void strategySetMenu(Menu associatedMenu) { + final MenuItem strategySetItem = new MenuItem(associatedMenu, SWT.NONE); + strategySetItem.setText(Messages.RemoveStrategyModel_Label); + strategySetItem.setImage(Activator.getDefault().getImage(Messages.RemoveStrategyModel_IconPath)); + strategySetItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + Collection<Resource> viewerResources = new LinkedList<Resource>(); + for (Object object : ((StructuredSelection) getViewer().getSelection()).toArray()) { + if (object instanceof Resource) { + viewerResources.add((Resource) object); + } + } + + getViewerInput().getResources().removeAll(viewerResources); + } + }); + } + + /** + * Initialize the SelectionChangedListener + */ + protected void initStrategySelectionListener() { + selectionChangedListener = new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + viewerSelection = event.getSelection(); + } + }; + } + + /** + * Method used to add new models + * + * @param resource + * The resource linked to the model + */ + public void addNewModel(Resource resource) { + if (getViewerInput() == null) { + getViewer().setInput(resource.getResourceSet()); + return; + } + + getViewerInput().getResources().add(resource); + } + + /** + * @return + * The current strategies selection + */ + public ISelection getStrategiesSelection() { + return viewerSelection; + } + + /** + * @return + * The viewer + */ + public TreeViewer getViewer() { + return filteredViewer.getViewer(); + } + + /** + * @return + * The names of the viewer's models + */ + public Collection<String> getViewerResourcesNames() { + ResourceSet viewerInput = getViewerInput(); + if (viewerInput == null) { + return new LinkedList<String>(); + } + + Collection<String> existingResources = new LinkedList<String>(); + for (Resource resource : viewerInput.getResources()) { + // List used to verify that the user is not adding an existing model in the viewer + existingResources.add(resource.getURI().lastSegment()); + } + + return existingResources; + } + + /** + * Get the viewer input, i.e. the elements contained in the tree + * + * @param viewer + * @return + * The resourceSet containing the models displayed in the viewer + */ + public ResourceSet getViewerInput() { + Object viewerInput = getViewer().getInput(); + if (viewerInput instanceof ResourceSet) { + return ((ResourceSet) viewerInput); + } + return null; + } + + /** + * Convenience method + * + * @return + * The list of the strategies in all the models present in the viewer + */ + public Collection<StrategyElement> getViewerStrategies() { + Collection<StrategyElement> viewerStrategies = new LinkedList<StrategyElement>(); + + for (Resource resource : getViewerInput().getResources()) { + EObject eObject = resource.getContents().get(0); + if (eObject instanceof StrategySet) { + StrategySet set = (StrategySet) eObject; + for (StrategyElement strategy : set.getStrategies()) { + viewerStrategies.add(strategy); + } + } + } + + return viewerStrategies; + } + + + // TODO implement dispose() + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTabRightViewerComposite.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTabRightViewerComposite.java new file mode 100755 index 00000000000..0856b5f3a56 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/AdvancedTabRightViewerComposite.java @@ -0,0 +1,568 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.pages; + +import java.util.ArrayList; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.CommonPlugin; +import org.eclipse.emf.common.notify.AdapterFactory; +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.edit.ui.provider.AdapterFactoryContentProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.papyrus.propertylifecycle.PropertylifecycleFactory; +import org.eclipse.papyrus.propertylifecycle.PropertylifecyclePackage; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.AdvancedTabLabelProvider; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.AdvancedTabViewerUtils; +import org.eclipse.papyrus.propertylifecycle.presentation.PropertylifecycleEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +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.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Tree; + +/** + * The Composite containing the right viewer of the advanced tab + * + */ +public class AdvancedTabRightViewerComposite extends Composite { + + /** The models containing the selected strategies */ + protected Map<String, String> parentModels; + + /** Factory used to get the information on the elements to populate the viewer */ + protected AdapterFactory adapterFactory; + + /** The viewer containing the selected strategies */ + protected TreeViewer treeViewer; + + /** The resourceSet containing the advanced Tab's custom model constructed by the user selected strategies */ + protected ResourceSet customStrategySetResourceSet; + + /** The set containing the selected strategies */ + protected StrategySet customStrategySet; + + /** The model containing the selected strategies */ + protected Resource strategySetResource; + + /** Factory used to construct the new custom model */ + protected PropertylifecycleFactory newModelFactory = PropertylifecycleFactory.eINSTANCE; + + /** The list of the selected strategies */ + protected Map<String, StrategyElement> viewerStrategies; + + /** Listener used to detect a different selection */ + protected ISelectionChangedListener selectionChangedListener; + + /** Listener used to identify the selected strategies */ + protected ISelection viewerSelection; + + + /** + * + * Constructor. + * + * @param parent + * The containing composite + * @param style + */ + public AdvancedTabRightViewerComposite(Composite parent, int style) { + super(parent, style); + this.setLayout(new GridLayout(1, true)); + // this.setLayout(new GridLayout(2, false)); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + // parentModels = new LinkedList<String>(); + parentModels = new HashMap<String, String>(); + + PropertylifecycleEditor contentEditor = new PropertylifecycleEditor(); + adapterFactory = contentEditor.getAdapterFactory(); + viewerStrategies = new HashMap<String, StrategyElement>(); + + initStrategySelectionListener(); + createViewer(this); + initViewer(); + } + + /** + * Create the viewer and its associated popup menus + * + * @param parent + * this + */ + protected void createViewer(Composite parent) { + treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); + treeViewer.setLabelProvider(new AdvancedTabLabelProvider(adapterFactory)); + + treeViewer.addSelectionChangedListener(selectionChangedListener); + + Tree tree = getViewer().getTree(); + final Menu rightClickMenu = new Menu(tree); + tree.setMenu(rightClickMenu); + rightClickMenu.addMenuListener(new MenuAdapter() { + + @Override + public void menuShown(MenuEvent e) { + MenuItem[] items = rightClickMenu.getItems(); + for (int i = 0; i < items.length; i++) { + items[i].dispose(); + } + + if (((StructuredSelection) viewerSelection).getFirstElement() instanceof StrategyElement) { + strategyMenu(rightClickMenu); + } + + if (((StructuredSelection) viewerSelection).getFirstElement() instanceof StrategyElement) { + strategySetMenu(rightClickMenu); + } + + } + }); + + } + + /** + * Create the menu item controlling the removal of the selected strategies + * + * @param associatedMenu + * The parent menu + */ + private void strategyMenu(Menu associatedMenu) { + final MenuItem configurationItem = new MenuItem(associatedMenu, SWT.NONE); + configurationItem.setText(Messages.RemoveStrategy_Label); + configurationItem.setImage(Activator.getDefault().getImage(Messages.RemoveStrategy_IconPath)); + configurationItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + StrategySet customSet = (StrategySet) getViewerInput().getResources().get(0).getContents().get(0); + Collection<StrategyElement> strategiesToRemove = new LinkedList<StrategyElement>(); + + for (Object object : ((StructuredSelection) viewerSelection).toArray()) { + if (object instanceof StrategyElement) { + strategiesToRemove.add((StrategyElement) object); + } + } + + for (StrategyElement strategy : strategiesToRemove) { + customSet.getStrategies().remove(strategy); + viewerStrategies.remove(strategy.getId()); + } + + } + }); + } + + /** + * Create the menu item controlling the removal of the selected model + * + * @param associatedMenu + * The parent menu + */ + private void strategySetMenu(Menu associatedMenu) { + final MenuItem strategySetItem = new MenuItem(associatedMenu, SWT.NONE); + strategySetItem.setText(Messages.RemoveAllStrategies_Label); + strategySetItem.setImage(Activator.getDefault().getImage(Messages.RemoveAllStrategies_IconPath)); + strategySetItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + StrategySet customSet = (StrategySet) getViewerInput().getResources().get(0).getContents().get(0); + + for (StrategyElement strategy : getViewerStrategySet().getStrategies()) { + viewerStrategies.remove(strategy.getId()); + } + + customSet.getStrategies().clear(); + + } + }); + } + + /** + * @return + * The viewer + */ + public TreeViewer getViewer() { + return treeViewer; + } + + /** + * Initialize the listener used to retrieve the selected items + */ + protected void initStrategySelectionListener() { + selectionChangedListener = new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + viewerSelection = event.getSelection(); + } + }; + } + + /** + * Initialize the viewer contents + */ + protected void initViewer() { + customStrategySetResourceSet = new ResourceSetImpl(); + // configurationResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMLResourceFactoryImpl()); + // configurationResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); + + // Default behavior + initFromScratch(); + + getViewer().refresh(); + } + + /** + * Create the viewer contents if no previous activity/selection existed + */ + private void initFromScratch() { + // Only launch if there were no previously constructed resource + // Creates the root object for the custom model + customStrategySet = newModelFactory.createStrategySet(); + customStrategySet.setId("CustomConfiguration"); //$NON-NLS-1$ + // Empty resourceSet to be filled by the custom selection of the user + URI fileURI = CommonPlugin.resolve(URI.createFileURI(Platform.getLocation().toOSString() + "/Custom.propertylifecyclestrategyset")); //$NON-NLS-1$ + // URI fileURI = URI.createFileURI(Platform.getLocation().toOSString() + "/Custom.renamestrategiesconfigurations"); //$NON-NLS-1$ + strategySetResource = customStrategySetResourceSet.createResource(fileURI, PropertylifecyclePackage.eCONTENT_TYPE); + strategySetResource.getContents().add(customStrategySet); + + getViewer().setInput(customStrategySetResourceSet); + + expandToLevel(1); + } + + /** + * Utility method used to expand the tree + * + * @param level + * The required level + */ + private void expandToLevel(int level) { + // Search the tree for the Set and expand from there to reveal the strategies if any exists + getViewer().expandToLevel(getViewerInput().getResources().get(0), level); + } + + /** + * @return + * The viewer's contents + */ + public ResourceSet getViewerInput() { + Object viewerInput = getViewer().getInput(); + if (viewerInput instanceof ResourceSet) { + return ((ResourceSet) viewerInput); + } + return null; + } + + /** + * Add method, pointing to {@link #addStrategies(Collection)} + * + * @param selection + * The selected items from another viewer + */ + public void addStrategies(ISelection selection) { + if (!(selection instanceof StructuredSelection)) { + return; + } + Collection<?> selectedElements = ((StructuredSelection) selection).toList(); + + addStrategies(selectedElements); + } + + /** + * Add method, pointing to {@link #addStrategies(Collection)} + * + * @param resourceSet + * The selected items from another source + */ + public void addStrategies(ResourceSet resourceSet) { + Collection<Resource> resources = new LinkedList<Resource>(); + for (Resource resource : resourceSet.getResources()) { + resources.add(resource); + } + + addStrategies(resources); + } + + /** + * Main add method + * + * @param selection + * The selected strategies + */ + public void addStrategies(Collection<?> selection) { + // Copy of the selection to update as the cases are treated + Collection<Object> remainingSelection = new ArrayList<Object>(selection); + Collection<StrategyElement> selectedStrategies = new LinkedList<StrategyElement>(); + + // First - extract the strategies from the inputed resources and delete these from the remaining selection + for (Object object : selection) { + if (!(object instanceof Resource)) { + continue; + } + + for (Object resourceContent : ((Resource) object).getContents()) { + if (!(resourceContent instanceof StrategySet)) { + continue; + } + + // This will only be the case if the user has selected both the resource and the contained set + StrategySet strategySet = (StrategySet) resourceContent; + if (remainingSelection.contains(strategySet)) { + // In this case, the configurations of the set will be revealed by getContentConfigurations + remainingSelection.remove(strategySet); + } + + List<StrategyElement> newStrategies = getContentStrategies(resourceContent); + // This will only be the case if the user has selected both the resource and the contained configuration + for (StrategyElement strategy : newStrategies) { + if (remainingSelection.contains(strategy)) { + remainingSelection.remove(strategy); + } + } + + selectedStrategies.addAll(newStrategies); + } + + if (remainingSelection.contains(object)) { + remainingSelection.remove(object); + } + } + + // Second - extract the strategies from the inputed sets and delete those from the remaining selection + List<Object> postResourceSelection = new ArrayList<Object>(remainingSelection); + for (Object object : postResourceSelection) { + if (!(object instanceof StrategySet)) { + continue; + } + + List<StrategyElement> newStrategies = getNewStrategySetStrategies((StrategySet) object); + // This case will occur if the user has selected a set and some of its contained configurations + for (StrategyElement strategy : newStrategies) { + if (remainingSelection.contains(strategy)) { + remainingSelection.remove(strategy); + } + } + + selectedStrategies.addAll(newStrategies); + } + + // Lastly - extract the remaining strategies to complete the selection + for (Object object : remainingSelection) { + if (!(object instanceof StrategyElement)) { + continue; + } + + StrategyElement remainigStrategy = (StrategyElement) object; + if (!(viewerStrategies.containsKey(remainigStrategy.getId()))) { + viewerStrategies.put(remainigStrategy.getId(), remainigStrategy); + selectedStrategies.add(remainigStrategy); + } + } + + populateViewer(selectedStrategies); + } + + /** + * Used to extract the strategies from the set @see RenameSetConfiguration + * + * @param object + * The set + * @return + * The list of the contained strategies or an empty list + */ + private List<StrategyElement> getContentStrategies(Object object) { + List<StrategyElement> contentStrategies = new LinkedList<StrategyElement>(); + if (object instanceof StrategySet) { + return getNewStrategySetStrategies((StrategySet) object); + } + + return contentStrategies; + } + + /** + * Used to extract the strategies from the set @see RenameSetConfiguration + * + * @param strategySet + * The set + * @return + * The list of the contained strategies + */ + private List<StrategyElement> getNewStrategySetStrategies(StrategySet strategySet) { + List<StrategyElement> newStrategies = new LinkedList<StrategyElement>(); + for (StrategyElement strategy : strategySet.getStrategies()) { + if (viewerStrategies.containsKey(strategy.getId())) { + continue; + } + + viewerStrategies.put(strategy.getId(), strategy); + newStrategies.add(strategy); + } + + return newStrategies; + } + + /** + * Populates the viewer with the inputed strategies + * + * @param strategies + * The selected strategies + */ + private void populateViewer(Collection<StrategyElement> strategies) { + + for (StrategyElement strategy : strategies) { + setParentModelsURI(strategy); + + // This will remove the configuration from the left viewer to add it to the right one + // newRenameSetConfiguration.getConfigurations().add((RenameConfiguration) configuration); + + // getViewerStrategySet().getStrategies().add(AdvancedTabViewerUtils.getnewStrategy(strategy)); + getViewerStrategySet().getStrategies().add(AdvancedTabViewerUtils.cloneStrategy(strategy)); + viewerStrategies.put(strategy.getId(), strategy); + } + + // Search the tree for the Set and expand one more level from there + if (!getViewer().getExpandedState(getViewerStrategySet()) || !getViewer().getExpandedState(customStrategySetResourceSet)) { + getViewer().expandToLevel(getViewerStrategySet(), 1); + } + getViewer().refresh(); + } + + /** + * Add the URI of the model containing the added strategy to the list of handled models + * + * @param renameConfiguration + * The added strategy + */ + private void setParentModelsURI(StrategyElement strategy) { + StrategySet strategySet = (StrategySet) strategy.eContainer(); + String setURI = strategySet.eResource().getURI().toString(); + // if (!parentModels.contains(setURI)) { + // parentModels.add(setURI); + // } + if (!parentModels.containsKey(strategy.getId())) { + parentModels.put(strategy.getId(), setURI); + } + } + + /** + * @return + * The parent models of the selected strategies + */ + public Collection<String> getParentModels() { + HashSet<String> usedModels = new HashSet<String>(); + for (String key : parentModels.keySet()) { + usedModels.add(parentModels.get(key)); + } + + return usedModels; + } + + /** + * Remove the selected configurations from the viewer and their associated model from the parent list of necessary + */ + protected void removeSelectedStrategies() { + @SuppressWarnings("unchecked") + List<StrategyElement> strategiesToRemove = viewerSelection instanceof StructuredSelection ? ((StructuredSelection) viewerSelection).toList() : new LinkedList<StrategyElement>(); + getViewerStrategySet().getStrategies().removeAll(strategiesToRemove); + for (StrategyElement renameConfiguration : strategiesToRemove) { + viewerStrategies.remove(renameConfiguration.getId()); + parentModels.keySet().removeAll(Collections.singleton(renameConfiguration.getId())); + } + + getViewer().refresh(); + } + + /** + * @return + * The strategy set build inside this viewer + */ + private StrategySet getViewerStrategySet() { + if (getViewerInput().getResources().get(0).getContents().get(0) instanceof StrategySet) { + return (StrategySet) getViewerInput().getResources().get(0).getContents().get(0); + } + return null; + } + + /** + * @return + * The strategies selected in this viewer + */ + public Collection<StrategyElement> getViewerStrategies() { + return getViewerStrategySet().getStrategies(); + } + + /** + * Clear all the strategies from the viewer and their associated lists + */ + protected void removeAllStrategies() { + getViewerStrategies().clear(); + viewerStrategies.clear(); + parentModels.clear(); + + getViewer().refresh(); + } + + /** + * @return + * The resource containing the strategy set build inside this viewer + */ + public Resource getStrategiesModelResource() { + return strategySetResource = getViewerInput().getResources().get(0); + } + + /** + * @return + * The state of the viewer + */ + protected boolean isEmpty() { + // The second condition can be achieved if the user added an empty selection to an empty tree + if (getViewer().getTree().getItems().length > 0 && customStrategySet != null) { + return false; + } + return true; + } + + + // TODO implement dispose() + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/BasicTab.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/BasicTab.java new file mode 100755 index 00000000000..72864d16d85 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/BasicTab.java @@ -0,0 +1,413 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.pages; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.BrowseButton; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +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.Display; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +/** + * Handle the creation of the basic tab of the preference page + * + */ +public class BasicTab implements SelectionListener { + + /** Viewer displaying the strategy models declared in the registry by extension or imported by the user */ + protected TableViewer tableViewer; + + /** The table contained in the viewer */ + protected Table table; + + /** The composite containing the buttons controlling the selection and browsing */ + protected Composite controlComposite; + + /** Select all the models */ + protected Button selectAllButton; + + /** Deselect all the models */ + protected Button deselectAllButton; + + /** Map of the selected models */ + protected Map<Resource, String> selectedModels; + + /** Color indicating a selected model or used in the advanced tab */ + protected Color colorBlack = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + + /** Color indicating an unselected model */ + protected Color colorGrey = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + + /** + * + * Constructor. + * + * @param parent + * The parent composite + * @param style + */ + public BasicTab(CTabFolder parent, int style) { + CTabItem basicTabItem = new CTabItem(parent, SWT.NONE); + basicTabItem.setText("Basic Selection"); + + selectedModels = new HashMap<Resource, String>(); + Composite basicTabComposite = new Composite(parent, style); + basicTabComposite.setLayout(new GridLayout(2, false)); + basicTabComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + basicTabItem.setControl(basicTabComposite); + + createTableViewer(basicTabComposite); + createControlsComposite(basicTabComposite); + } + + /** + * Create the viewer + * + * @param parent + * The parent composite + */ + private void createTableViewer(final Composite parent) { + table = new Table(parent, SWT.MULTI | SWT.BORDER); + tableViewer = new TableViewer(table); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + tableViewer.setContentProvider(new ArrayContentProvider() { + + @Override + /** Override used to get the list of the displayed resource in order to */ + public Object[] getElements(Object inputElement) { + Collection<Resource> resources = new LinkedList<Resource>(); + if (inputElement instanceof ResourceSet) { + for (Resource resource : ((ResourceSet) inputElement).getResources()) { + resources.add(resource); + } + return resources.toArray(); + } + return super.getElements(inputElement); + } + }); + + table.setHeaderVisible(true); + table.setLinesVisible(true); + + TableViewerColumn checkbox = createTableViewerColumn("", 22, tableViewer); + checkbox.getColumn().setResizable(false); + checkbox.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return ""; //$NON-NLS-1$ + } + + @Override + // Set the toggle boxes + public Image getImage(Object element) { + if (selectedModels.containsKey(element)) { + return Activator.getDefault().getImage(Messages.Checked_IconPath); + } else { + return Activator.getDefault().getImage(Messages.Unchecked_IconPath); + } + } + }); + // Set the toggle boxes behavior + checkbox.setEditingSupport(new EditingSupport(tableViewer) { + + private CheckboxCellEditor checkboxCellEditor; + + @Override + protected CellEditor getCellEditor(Object element) { + // The new visual + checkboxCellEditor = new CheckboxCellEditor(parent, SWT.CHECK | SWT.READ_ONLY); + return checkboxCellEditor; + } + + @Override + protected boolean canEdit(Object element) { + // Always true + return true; + } + + @Override + protected Object getValue(Object element) { + // Check if the model is currently selected + return selectedModels.containsKey(element); + } + + @Override + protected void setValue(Object element, Object value) { + Resource resource = element instanceof Resource ? ((Resource) element) : null; + // This line's object object is not correctly formated + if (resource == null) { + return; + } + + // Update the list of selected models + if (checkboxCellEditor.getValue() == Boolean.TRUE) { + selectedModels.put(resource, resource.getURI().lastSegment()); + } else { + selectedModels.remove(resource); + } + + // Update the visual of the table + tableViewer.update(element, null); + } + }); + + + TableViewerColumn modelColumn = createTableViewerColumn("model", 300, tableViewer); + modelColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + // Get the name of the file handled + return element instanceof Resource ? ((Resource) element).getURI().lastSegment().toString() : super.getText(element); + } + }); + + TableViewerColumn descriptionColumn = createTableViewerColumn("description", 300, tableViewer); + descriptionColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + // Get the description, if any, of the model + Resource resource = element instanceof Resource ? ((Resource) element) : null; + Object setResource = resource.getContents().get(0); + return setResource instanceof StrategySet ? ((StrategySet) setResource).getDecription() : "N/A"; + } + }); + } + + /** + * Color scheme of the lines + * + * @param lastSegs + * The file names + */ + protected void setItemColor(Set<String> lastSegs) { + for (TableItem item : table.getItems()) { + String lastSeg = item.getData() instanceof Resource ? ((Resource) item.getData()).getURI().lastSegment() : "NA"; + if (lastSegs.contains(lastSeg)) { + item.setForeground(1, colorBlack); + item.setForeground(2, colorBlack); + // item.setForeground(null); + } else { + item.setForeground(1, colorGrey); + item.setForeground(2, colorGrey); + } + } + } + + /** + * Generic creator of the columns + * + * @param header + * The name of the column + * @param width + * The width of the column + * @param parentViewer + * The associated viewer + * @return + * The new {@link #org.eclipse.jface.viewers.TableViewerColumn column} + */ + protected TableViewerColumn createTableViewerColumn(String header, int width, TableViewer parentViewer) { + TableViewerColumn newColumn = new TableViewerColumn(parentViewer, SWT.BORDER); + TableColumn column = newColumn.getColumn(); + column.setWidth(width); + column.setText(header); + column.setResizable(true); + column.setMoveable(false); + + return newColumn; + } + + /** + * Create the control composite containing the selection and browsing buttons + * + * @param parent + * The parent composite + */ + protected void createControlsComposite(Composite parent) { + controlComposite = new Composite(parent, SWT.NONE); + controlComposite.setLayout(new GridLayout(1, true)); + GridData controlLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + controlComposite.setLayoutData(controlLayoutData); + + selectAllButton = new Button(controlComposite, SWT.PUSH); + selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + selectAllButton.addSelectionListener(this); + selectAllButton.setToolTipText(Messages.SelectAllButton_Label); + selectAllButton.setText(Messages.SelectAllButton_Label); + + deselectAllButton = new Button(controlComposite, SWT.PUSH); + deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + deselectAllButton.addSelectionListener(this); + deselectAllButton.setToolTipText(Messages.DeselectAllButton_Label); + deselectAllButton.setText(Messages.DeselectAllButton_Label); + + new BrowseButton(controlComposite, getViewer()); + } + + /** + * Link the selection events with the correct methods + * + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + * + * @param e + * The selection event + */ + @Override + public void widgetSelected(SelectionEvent e) { + if (e.widget == selectAllButton) { + selectAllAction(); + } else if (e.widget == deselectAllButton) { + deselectAllAction(); + } + } + + /** + * Select all the items present in the viewer + */ + public void selectAllAction() { + for (TableItem item : table.getItems()) { + Resource resource = (Resource) item.getData(); + selectedModels.put(resource, resource.getURI().lastSegment()); + getViewer().update(resource, null); + } + } + + /** + * Deselect all the models present in the viewer + */ + public void deselectAllAction() { + for (TableItem item : table.getItems()) { + Resource resource = (Resource) item.getData(); + selectedModels.remove(resource); + getViewer().update(resource, null); + } + } + + /** + * Method used to initialize the selection in the viewer based on the current preferences + * + * @param filePaths + * The currently active strategy models' {@link #org.eclipse.emf.common.util.URI URI} + */ + public void initSelection(Collection<String> filePaths) { + for (String filePath : filePaths) { + String preferenceKey = (URI.createPlatformPluginURI(filePath, true)).lastSegment(); + for (TableItem item : table.getItems()) { + Resource resource = (Resource) item.getData(); + String resourceKey = resource.getURI().lastSegment(); + + if (preferenceKey.equals(resourceKey)) { + selectedModels.put(resource, resourceKey); + getViewer().update(resource, null); + } + } + } + } + + /** + * Clear any selected models that are not declared in the registry and reset the selection to the default state + * + * @param registryResourceSet + * The {@link #org.eclipse.emf.ecore.resource.ResourceSet resourceSet} containing the models + */ + public void removeNonRegistryModels(ResourceSet registryResourceSet) { + table.clearAll(); + selectedModels.clear(); + tableViewer.setInput(registryResourceSet); + selectAllAction(); + } + + /** + * Convenience method used to initialize the viewer from the parent Composite + */ + public void defaultSelection() { + selectAllAction(); + } + + /** + * @return + * The selected models + */ + public Collection<String> getSelectedModels() { + Collection<String> selectedModelsURI = new LinkedList<String>(); + for (Resource resource : selectedModels.keySet()) { + selectedModelsURI.add(resource.getURI().toString()); + } + + return selectedModelsURI; + } + + /** + * @return + * The selected models' strategies + */ + public HashSet<StrategyElement> getSelectedStrategies() { + HashSet<StrategyElement> selectedStrategies = new HashSet<StrategyElement>(); + for (Resource resource : selectedModels.keySet()) { + if (resource.getContents().get(0) instanceof StrategySet) { + selectedStrategies.addAll(((StrategySet) resource.getContents().get(0)).getStrategies()); + } + } + + return selectedStrategies; + } + + /** + * Convenience method + * + * @return + * This composite's Viewer + */ + public StructuredViewer getViewer() { + return tableViewer; + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // nothing + } + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/PropertyLifecyclePageComposite.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/PropertyLifecyclePageComposite.java new file mode 100755 index 00000000000..5b1546a04aa --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/PropertyLifecyclePageComposite.java @@ -0,0 +1,248 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.pages; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +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.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.model.registries.StrategySetRegistry; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.BrowserUtils; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.PropertyLifecyclePreferencesManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + + +/** + * This Composite is the root of the Basic and Advanced Tabs showing the selected and possible strategies + * + */ +public class PropertyLifecyclePageComposite extends CTabFolder { + + /** This collection contains the resources referenced in an extension and retrievable from the registry */ + private Collection<Resource> registryResources; + + /** This tab will show the entire resources as a whole entity */ + protected BasicTab basicTab; + + /** In this tab the resources will display all the underlying strategies for the user to choose from */ + protected AdvancedTab advancedTab; + + // BEGIN TEST-GREYOUT + /** This set is used to visualize the currently selected strategies */ + private Set<String> handledStrategyRepositories = new HashSet<String>(); + // END TEST-GREYOUT + + + /** + * + * Constructor. + * + * @param parent + * The parent composite used to harbor this one + * @param style + * The border style of this composite + */ + public PropertyLifecyclePageComposite(Composite parent, int style) { + super(parent, style); + this.setLayout(new GridLayout()); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + createBasicTab(); + createAdvancedTab(); + + initViewers(); + this.setSelection(0); + } + + /** + * Creates the Basic selection tab + */ + private void createBasicTab() { + basicTab = new BasicTab(this, SWT.BORDER) { + // BEGIN TEST-GREYOUT + @Override + public void selectAllAction() { + super.selectAllAction(); + getSelectedStrategyRepositories(); + } + + @Override + public void deselectAllAction() { + super.deselectAllAction(); + getSelectedStrategyRepositories(); + } + }; + + basicTab.getViewer().addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + getSelectedStrategyRepositories(); + } + }); + // END TEST-GREYOUT + } + + /** + * Creates the advanced selection tab + */ + private void createAdvancedTab() { + advancedTab = new AdvancedTab(this, SWT.BORDER) { + // BEGIN TEST-GREYOUT + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + getSelectedStrategyRepositories(); + } + // END TEST-GREYOUT + }; + } + + /** + * Call the necessary methods to populate the basic and advanced tabs + */ + private void initViewers() { + // clearViewers(); + + // Load the Registry strategySet models as a default behavior + addRegistryStrategiesToViewers(); + + // Retrieve the previous preferences + PropertyLifecyclePreferencesManager preferencesManager = new PropertyLifecyclePreferencesManager(); + BrowserUtils.addBrowsedModel(preferencesManager.retrieveAdvancedTabModelPaths(), advancedTab.getLeftViewer()); + BrowserUtils.addBrowsedModel(preferencesManager.retrieveBasicTabModelPaths(), basicTab.getViewer()); + + // Initialize the viewers' selections + basicTab.initSelection(preferencesManager.retrieveBasicTabModelPaths()); + if (!preferencesManager.nodeExists(Messages.BasicBrowsedModels_Node)) { + // The Default behavior, if the user has not deactivated all the models, is to preselect all + // basicTab.defaultSelection(); + } + advancedTab.addStrategies(preferencesManager.retrieveAdvancedTabStrategies()); + + getSelectedStrategyRepositories(); + } + + /** + * Retrieve the resources referenced in the registry + */ + private void addRegistryStrategiesToViewers() { + ResourceSet resourceSet = new ResourceSetImpl(); + registryResources = new HashSet<Resource>(); + Map<String, StrategySet> strategySets = StrategySetRegistry.getInstance().getStrategySets(); + if (strategySets != null) { + for (String setKey : strategySets.keySet()) { + StrategySet strategySet = strategySets.get(setKey); + resourceSet.getResources().add(strategySet.eResource()); + registryResources.add(strategySet.eResource()); + } + } + + advancedTab.getLeftViewer().setInput(resourceSet); + basicTab.getViewer().setInput(resourceSet); + } + + /** + * Clear the viewers to their default state + */ + public void resetViewers() { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResources().addAll(registryResources); + + advancedTab.removeAllSelectionCompositeStrategies(); + advancedTab.setRegisteredCompositeInput(resourceSet); + basicTab.removeNonRegistryModels(resourceSet); + } + + /** + * Get the adresses of the selected resources from the basic tab + * + * @return + */ + public Collection<String> getBasicParentModels() { + return basicTab.getSelectedModels(); + } + + /** + * Get the resulting selected strategies from the selected resources + * + * @return + */ + public Collection<StrategyElement> getBasicStrategies() { + return basicTab.getSelectedStrategies(); + } + + /** + * Get the adresses of the selected resources from the advanced tab + * + * @return + */ + public Collection<String> getAdvancedParentModels() { + return advancedTab.getAdvancedParentModels(); + } + + /** + * Get the resulting strategies from the selected resources + * + * @return + */ + public Collection<StrategyElement> getAdvancedStrategies() { + return advancedTab.getAdvancedStrategies(); + } + + /** + * Get the currently selected resources and initiate the corresponding visual representation + * + * @return + * The list of the selected addresses + */ + private Set<String> getSelectedStrategyRepositories() { + handledStrategyRepositories.clear(); + if (advancedTab.rightViewerComposite == null || basicTab == null) { + return new HashSet<String>(); + } + + for (String modelName : advancedTab.rightViewerComposite.getParentModels()) { + URI test = URI.createFileURI(modelName); + handledStrategyRepositories.add(test.lastSegment()); + } + for (String modelName : basicTab.getSelectedModels()) { + URI test = URI.createFileURI(modelName); + handledStrategyRepositories.add(test.lastSegment()); + } + + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, handledStrategyRepositories.toString()); + basicTab.setItemColor(handledStrategyRepositories); + return handledStrategyRepositories; + } + + // TODO implement dispose() + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/PropertyLifecyclePreferencesPage.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/PropertyLifecyclePreferencesPage.java new file mode 100755 index 00000000000..1830ad5d441 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/pages/PropertyLifecyclePreferencesPage.java @@ -0,0 +1,113 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.pages; + + +//import org.eclipse.jface.action.Action; +//import org.eclipse.papyrus.infra.propertylifecycle.preferences.utils.ConvertEcoreToUML; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.papyrus.propertylifecycle.preferences.utils.PropertyLifecyclePreferencesManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * Preference Page initiating the creation of its contents and the update of the selected preferences + * + */ +public class PropertyLifecyclePreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { + + /** The preferenceManager used to handle the previous and current preferences on the strategies */ + private PropertyLifecyclePreferencesManager preferencesManager = new PropertyLifecyclePreferencesManager(); + + /** The root composite containing the page's contents */ + private PropertyLifecyclePageComposite propertyLifecyclePageComposite; + + /** + * Constructor. + */ + public PropertyLifecyclePreferencesPage() { + super(Messages.PropertyLifecycle_PreferencePage_Title, Activator.getDefault().getImageDescriptor("/icons/papyrus.png")); //$NON-NLS-1$ + } + + /** + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + * + * @param workbench + */ + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setDescription(Messages.Choose_Configuration); + } + + /** + * Method used to initialize the composite before applying the visual effects linked to the selected strategies + * + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + * + * @param parent + * @return + * parent + */ + @Override + public Control createContents(Composite parent) { + initializeDialogUnits(parent); + propertyLifecyclePageComposite = new PropertyLifecyclePageComposite(parent, SWT.NONE); + return parent; + } + + /** + * Get all the selected strategies and register them through the PreferenceManager + * + * @see org.eclipse.jface.preference.PreferencePage#performApply() + * + */ + @Override + protected void performApply() { + preferencesManager.registerCurrentPreferences( + propertyLifecyclePageComposite.getBasicParentModels(), + propertyLifecyclePageComposite.getAdvancedParentModels(), + propertyLifecyclePageComposite.getBasicStrategies(), + propertyLifecyclePageComposite.getAdvancedStrategies()); + + // ConvertEcoreToUML convertDialog = new ConvertEcoreToUML(); + // convertDialog.run(new Action() { + // }); + + super.performApply(); + } + + /** + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + * + */ + @Override + protected void performDefaults() { + preferencesManager.clearPreferences(); + propertyLifecyclePageComposite.resetViewers(); + + super.performDefaults(); + } + + @Override + public void performHelp() { + // do something ? + } +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/AdvancedTabLabelProvider.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/AdvancedTabLabelProvider.java new file mode 100755 index 00000000000..1bc58d072be --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/AdvancedTabLabelProvider.java @@ -0,0 +1,109 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; +import org.eclipse.papyrus.propertylifecycle.ElementContainer; +import org.eclipse.papyrus.propertylifecycle.ElementProperty; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.eclipse.swt.graphics.Image; + +/** + * Class used to specialize the label provider of the advanced tab viewers + * + */ +public class AdvancedTabLabelProvider extends AdapterFactoryLabelProvider { + + /** + * Constructor. + * + * @param adapterFactory + * The factory used as a base + */ + public AdvancedTabLabelProvider(AdapterFactory adapterFactory) { + super(adapterFactory); + } + + /** + * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider#getText(java.lang.Object) + * + * @param object + * The viewer element + * @return + * The labels to be displayed + */ + @Override + public String getText(Object object) { + StringBuilder label = new StringBuilder(); + + if (object instanceof Resource) { + return ((Resource) object).getURI().lastSegment(); + } + if (object instanceof StrategyElement) { + label.append(Messages.StrategyElement_Label); + String elementType = ((StrategyElement) object).getBaseType(); + label.append(elementType); + return label.toString(); + } + if (object instanceof ElementProperty) { + label.append(Messages.ElementProperty_Label); + String featureLabel = ((ElementProperty) object).getFeatureLabel(); + label.append(featureLabel); + return label.toString(); + } + if (object instanceof ElementContainer) { + label.append(Messages.ElementContainer_Label); + String containerType = ((ElementContainer) object).getBaseType(); + label.append(containerType); + return label.toString(); + } + + return super.getText(object); + } + + /** + * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider#getImage(java.lang.Object) + * + * @param object + * The viewer element + * @return + * The image to be displayed + */ + @Override + public Image getImage(Object object) { + if (object instanceof Resource) { + return Activator.getDefault().getImage(Messages.Resource_IconPath); + } + if (object instanceof StrategySet) { + return Activator.getDefault().getImage(Messages.StrategySet_IconPath); + } + if (object instanceof StrategyElement) { + return Activator.getDefault().getImage(Messages.Strategy_IconPath); + } + if (object instanceof ElementProperty) { + return Activator.getDefault().getImage(Messages.Property_IconPath); + } + if (object instanceof ElementContainer) { + return Activator.getDefault().getImage(Messages.ElementContainer_IconPath); + } + + return super.getDefaultImage(object); + } + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/AdvancedTabViewerUtils.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/AdvancedTabViewerUtils.java new file mode 100755 index 00000000000..b56abf13c8d --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/AdvancedTabViewerUtils.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.propertylifecycle.PropertylifecycleFactory; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; + +/** + * Convenience class used to create the custom model and its strategies + * + */ +public class AdvancedTabViewerUtils { + + /** The factory from which all the strategies are spawned */ + protected static PropertylifecycleFactory newModelFactory = PropertylifecycleFactory.eINSTANCE; + + /** + * Clone the selected strategy in the custom model + * + * @param selectedStrategy + * The selected strategy + * @return + * The cloned strategy + */ + public static StrategyElement cloneStrategy(StrategyElement selectedStrategy) { + StrategyElement clonedStrategy = EcoreUtil.copy(selectedStrategy); + + return clonedStrategy; + } + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/BrowseButton.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/BrowseButton.java new file mode 100755 index 00000000000..cb69009f7ac --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/BrowseButton.java @@ -0,0 +1,117 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +import java.io.File; +import java.util.Collection; +import java.util.LinkedList; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +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.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; + +/** + * Class used to create the browser button and its associated window + * + */ +public class BrowseButton { + + /** The file extensions */ + private static String[] filterExtensions = { "*.propertylifecycle", "*" }; //$NON-NLS-1$ //$NON-NLS-2$ + + /** Their associated names in the window's scrolling menu */ + private static String[] filterExtensionsNames = { "Strategies Sets", "All" }; //$NON-NLS-1$ //$NON-NLS-2$ + + /** The button's parent composite */ + protected Composite parent; + + /** The viewer to receive the fetched model */ + protected Viewer viewer; + + + /** + * Constructor. + * + * @param parent + * @param viewer + */ + public BrowseButton(final Composite parent, final Viewer viewer) { + this.parent = parent; + this.viewer = viewer; + + createBrowserButton(this.parent); + // TODO implement a link to grey-out the imported model + } + + /** + * @return + * The browser button used to fetch the strategy models from the user's disk and add it is not already loaded + */ + public Button createBrowserButton(Composite parent) { + Button browseButton = new Button(parent, SWT.NONE); + // browseButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); + browseButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + browseButton.setText(Messages.BrowseButton_Label); + + browseButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + FileDialog dialog = new FileDialog(parent.getShell(), SWT.MULTI); + dialog.setText(Messages.SystemSelectionDialog_Title); + dialog.setFilterExtensions(filterExtensions); + dialog.setFilterNames(filterExtensionsNames); + + Collection<String> newSystemPaths = new LinkedList<String>(); + Collection<String> existingResources = BrowserUtils.getViewerResources(viewer); + + String dialogResult = dialog.open(); + if (dialogResult == null) { + return; + } + // Settings - Store the last folder/directory visited + String[] names = dialog.getFileNames(); + + // Empty the list to avoid remembering old selections + for (int i = 0, n = names.length; i < n; i++) { + StringBuffer buf = new StringBuffer(dialog.getFilterPath()); + if (buf.charAt(buf.length() - 1) != File.separatorChar) { + buf.append(File.separatorChar); + } + buf.append(names[i]); + + if (existingResources.contains(names[i])) { + continue; + } + + newSystemPaths.add(buf.toString()); + } + + BrowserUtils.addBrowsedModel(newSystemPaths, viewer); + } + }); + + return browseButton; + } + + + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/BrowserUtils.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/BrowserUtils.java new file mode 100755 index 00000000000..bbe897953f0 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/BrowserUtils.java @@ -0,0 +1,156 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; + +import org.eclipse.emf.common.CommonPlugin; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; + +/** + * Convenience class regrouping methods to retrieve model resources + * + */ +public class BrowserUtils { + + /** + * Add the browsed models to the viewer + * + * @param newSystemPaths + * The selected models' paths + * @param viewer + * The viewer that will receive these new models + */ + public static void addBrowsedModel(Collection<String> newSystemPaths, Viewer viewer) { + + for (String filePath : newSystemPaths) { + Resource resource = getModelResource(filePath); + if (resource == null || getViewerResources(viewer).contains(resource.getURI().lastSegment())) { + continue; + } + + EObject content = resource.getContents().get(0); + if (content instanceof StrategySet) { + // Preferences browsedNode = renamePreferences.node(Messages.BrowsedModels_Node); + // browsedNode.putBoolean(filePath, true); + addNewModel(resource, viewer); + } + } + + viewer.refresh(); + } + + /** + * @param filePath + * The path of the selected model + * @return + * The resource associated to this path or null if none can be retrieved + */ + public static Resource getModelResource(String filePath) { + URI fileURI = CommonPlugin.resolve(URI.createFileURI(filePath)); + // URI fileURI = URI.createFileURI(filePath); + ResourceSet resourceSet = new ResourceSetImpl(); + Resource resource = resourceSet.createResource(fileURI); + + try { + resource.load(null); + return resource; + } catch (IOException ioerror) { + Activator.log.error(ioerror); + } + return null; + } + + /** + * @param filePath + * The path of the selected model + * @return + * The strategy set associated to this path or null if none can be found + */ + public static StrategySet getStrategySet(String filePath) { + Resource resource = getModelResource(filePath); + if (resource == null) { + return null; + } + EObject eObject = resource.getContents().get(0); + + if (eObject instanceof StrategySet) { + return (StrategySet) eObject; + } + + return null; + } + + /** + * @param viewer + * The viewer receiving the inputed resource + * @return + * The viewer's current contents @see org.eclipse.emf.ecore.resource.ResourceSet + */ + public static ResourceSet getViewerInput(Viewer viewer) { + Object viewerInput = viewer.getInput(); + if (viewerInput instanceof ResourceSet) { + return ((ResourceSet) viewerInput); + } + return null; + } + + /** + * @param viewer + * The viewer receiving the inputed resource + * @return + * The viewer's current contents' identifiers + */ + public static Collection<String> getViewerResources(Viewer viewer) { + ResourceSet viewerInput = getViewerInput(viewer); + if (viewerInput == null) { + return new LinkedList<String>(); + } + + Collection<String> existingResources = new LinkedList<String>(); + for (Resource resource : viewerInput.getResources()) { + // List used to verify that the user is not adding an existing model in the viewer + existingResources.add(resource.getURI().lastSegment()); + } + + return existingResources; + } + + /** + * Add the browsed resource to the viewer + * + * @param resource + * The selected resource + * @param viewer + * The viewer to receive this resource + */ + public static void addNewModel(Resource resource, Viewer viewer) { + if (getViewerInput(viewer) == null) { + viewer.setInput(resource.getResourceSet()); + return; + } + + getViewerInput(viewer).getResources().add(resource); + } + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/ConvertEcoreToUML.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/ConvertEcoreToUML.java new file mode 100755 index 00000000000..ee8385baf55 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/ConvertEcoreToUML.java @@ -0,0 +1,251 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +// package org.eclipse.papyrus.rename.strategies.preferences.utils; +// +// import java.lang.reflect.InvocationTargetException; +// import java.util.ArrayList; +// import java.util.HashMap; +// import java.util.List; +// import java.util.Map; +// +// import org.eclipse.core.resources.IFile; +// import org.eclipse.core.runtime.IProgressMonitor; +// import org.eclipse.emf.common.command.UnexecutableCommand; +// import org.eclipse.emf.common.util.BasicDiagnostic; +// import org.eclipse.emf.common.util.Diagnostic; +// import org.eclipse.emf.common.util.EList; +// import org.eclipse.emf.common.util.TreeIterator; +// import org.eclipse.emf.common.util.URI; +// import org.eclipse.emf.ecore.EObject; +// import org.eclipse.emf.ecore.EPackage; +// import org.eclipse.emf.ecore.InternalEObject; +// import org.eclipse.emf.ecore.plugin.EcorePlugin; +// 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.xmi.XMIResource; +// import org.eclipse.jface.action.IAction; +// import org.eclipse.jface.dialogs.ProgressMonitorDialog; +// import org.eclipse.jface.operation.IRunnableWithProgress; +// import org.eclipse.jface.viewers.ISelection; +// import org.eclipse.jface.viewers.StructuredSelection; +// import org.eclipse.jface.window.Window; +// import org.eclipse.swt.widgets.Shell; +// import org.eclipse.ui.PlatformUI; +// import org.eclipse.uml2.common.util.UML2Util; +// import org.eclipse.uml2.examples.uml.ui.UMLExamplesUIPlugin; +// import org.eclipse.uml2.examples.uml.ui.dialogs.Ecore2UMLConverterOptionsDialog; +// import org.eclipse.uml2.uml.Element; +// import org.eclipse.uml2.uml.UMLPlugin; +// import org.eclipse.uml2.uml.editor.dialogs.OptionsDialog; +// import org.eclipse.uml2.uml.resource.UMLResource; +// import org.eclipse.uml2.uml.util.UMLUtil; +// import org.eclipse.uml2.uml.util.UMLValidator; +// +// +// /** +// * Need only import org.eclipse.uml2.examples.uml.ui and activate the action in the RenameStrategiesPreferencePage +// * +// */ +// public class ConvertEcoreToUML extends org.eclipse.uml2.examples.uml.ui.actions.ConvertToUMLModelAction { +// +// @Override +// public void run(IAction action) { +// +// if (command != UnexecutableCommand.INSTANCE) { +// ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); +// +// IFile iFile = (IFile) ((StructuredSelection) selection).getFirstElement(); +// ResourceSet resourceSet = new ResourceSetImpl(); +// Resource resource = resourceSet.createResource(URI.createPlatformResourceURI(iFile.getFullPath().toString(), true)); +// +// EObject content = null; +// try { +// resource.load(null); +// content = resource.getContents().get(0); +// } catch (Exception e) { +// // do something +// } +// +// if (!(content instanceof EPackage)) { +// return; +// } +// +// final EPackage ePackage = (EPackage) content; +// +// final Shell shell = PlatformUI.getWorkbench() +// .getActiveWorkbenchWindow().getShell(); +// +// final Map<String, String> options = new HashMap<String, String>(); +// +// final String label = UMLExamplesUIPlugin.INSTANCE.getString( +// "_UI_ConvertToUMLActionCommand_label", //$NON-NLS-1$ +// new Object[] { getObjectLabel(ePackage) }); +// +// OptionsDialog optionsDialog = new Ecore2UMLConverterOptionsDialog( +// shell, label, UMLExamplesUIPlugin.INSTANCE +// .getString("_UI_OptionsDialog_message"), //$NON-NLS-1$ +// options); +// +// if (optionsDialog.open() == Window.OK) { +// IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { +// +// @Override +// public void run(final IProgressMonitor progressMonitor) +// throws InvocationTargetException, +// InterruptedException { +// +// try { +// final BasicDiagnostic diagnostics = new BasicDiagnostic( +// UMLValidator.DIAGNOSTIC_SOURCE, 0, +// EcorePlugin.INSTANCE.getString( +// "_UI_DiagnosticRoot_diagnostic", //$NON-NLS-1$ +// new Object[] { getObjectLabel(ePackage) }), +// new Object[] { ePackage }); +// +// Map<Object, Object> context = new HashMap<Object, Object>(); +// context.put(UML2Util.QualifiedTextProvider.class, +// qualifiedTextProvider); +// +// progressMonitor.beginTask( +// UMLExamplesUIPlugin.INSTANCE.getString( +// "_UI_ConvertingToUML_message", //$NON-NLS-1$ +// new Object[] { getObjectLabel(ePackage) }), +// IProgressMonitor.UNKNOWN); +// +// Resource resource = ePackage.eResource(); +// ResourceSet resourceSet = resource.getResourceSet(); +// URI uri = resourceSet.getURIConverter().normalize( +// resource.getURI()).trimFileExtension() +// .trimSegments(1); +// +// List<Resource> resources = new ArrayList<Resource>(); +// +// for (org.eclipse.uml2.uml.Package package_ : UMLUtil +// .convertFromEcore(ePackage, options, +// diagnostics, context)) { +// +// resources.add(resource = resourceSet +// .createResource(uri.appendSegment( +// package_.getName()) +// .appendFileExtension( +// UMLResource.FILE_EXTENSION))); +// +// EList<EObject> contents = resource +// .getContents(); +// +// contents.add(package_); +// +// for (TreeIterator<EObject> allContents = UML2Util +// .getAllContents(package_, true, false); allContents +// .hasNext();) { +// +// EObject eObject = allContents.next(); +// +// if (eObject instanceof Element) { +// contents.addAll(((Element) eObject) +// .getStereotypeApplications()); +// } +// } +// +// if (UMLUtil.OPTION__PROCESS +// .equals(options +// .get(UMLUtil.Ecore2UMLConverter.OPTION__XMI_IDENTIFIERS)) +// && resource instanceof XMIResource) { +// +// XMIResource xmiResource = (XMIResource) resource; +// +// for (TreeIterator<EObject> allContents = xmiResource +// .getAllContents(); allContents +// .hasNext();) { +// +// EObject eObject = allContents.next(); +// String xmiIdentifier = UML2Util +// .getXMIIdentifier((InternalEObject) eObject); +// +// if (diagnostics != null) { +// diagnostics +// .add(new BasicDiagnostic( +// Diagnostic.INFO, +// UMLValidator.DIAGNOSTIC_SOURCE, +// UMLUtil.Ecore2UMLConverter.XMI_IDENTIFIER, +// UMLPlugin.INSTANCE +// .getString( +// "_UI_Ecore2UMLConverter_ProcessXMIIdentifier_diagnostic", //$NON-NLS-1$ +// UML2Util +// .getMessageSubstitutions( +// context, +// eObject, +// xmiIdentifier)), +// new Object[] { eObject })); +// } +// +// xmiResource.setID(eObject, +// xmiIdentifier); +// } +// } +// } +// +// for (Resource r : resources) { +// +// try { +// r.save(null); +// } catch (Exception e) { +// UMLExamplesUIPlugin.INSTANCE.log(e); +// } +// } +// +// handleDiagnostic(progressMonitor.isCanceled() +// ? Diagnostic.CANCEL_INSTANCE +// : diagnostics, label); +// } finally { +// progressMonitor.done(); +// } +// } +// }; +// +// if (eclipseResourcesUtil != null) { +// runnableWithProgress = eclipseResourcesUtil +// .getWorkspaceModifyOperation(runnableWithProgress); +// } +// +// try { +// new ProgressMonitorDialog(shell).run(false, true, +// runnableWithProgress); +// } catch (Exception e) { +// UMLExamplesUIPlugin.INSTANCE.log(e); +// } +// } +// } +// } +// +// public String getObjectLabel(EObject eObject) { +// Resource eResource = eObject.eResource(); +// +// String text = ""; +// if (eResource != null) { +// String lastSegment = eResource.getURI() +// .lastSegment(); +// +// if (lastSegment != null) { +// text += " - " + lastSegment; //$NON-NLS-1$ +// } +// } +// +// return text; +// } +// +// } diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/PropertyLifecyclePreferencesManager.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/PropertyLifecyclePreferencesManager.java new file mode 100755 index 00000000000..dddfa8613f6 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/PropertyLifecyclePreferencesManager.java @@ -0,0 +1,359 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.papyrus.propertylifecycle.StrategyElement; +import org.eclipse.papyrus.propertylifecycle.StrategySet; +import org.eclipse.papyrus.propertylifecycle.model.registries.StrategySetRegistry; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +/** + * Convenience class used to handle the preferences in one place + * + */ +public class PropertyLifecyclePreferencesManager { + + /** Preference node containing the strategies informations */ + // private Preferences renamePreferences = InstanceScope.INSTANCE.getNode(Messages.PreferenceRenameStrategies); + // We need to retain the preferences through multiple restarts + private Preferences propertyLifecyclePreferences = ConfigurationScope.INSTANCE.getNode(Messages.PropertyLifecycleStrategies); + + // Basic Tab + /** Set containing the selected models in the basic tab viewer */ + private HashSet<StrategySet> basicTabParentModels; + + /** Ids of the strategies contained in the selected models */ + private HashSet<String> basicTabStrategiesIDs; + + /** Addresses of the selected models */ + private HashSet<String> basicTabBrowsedModelsURI; + + /** strategies and their ids used to filter duplicates */ + private HashMap<String, StrategyElement> basicTabStrategies; + + // Advanced Tab + /** Set containing the selected models in the advanced tab viewer */ + private HashSet<StrategySet> advancedTabParentModels; + + /** Ids of the selected strategies */ + private HashSet<String> advancedTabStrategiesIDs; + + /** Addresses of the models containing the selected strategies */ + private HashSet<String> advancedTabBrowsedModelsURI; + + /** Strategies and their ids used to filter duplicates */ + private HashMap<String, StrategyElement> advancedTabStrategies; + + + /** + * Build the skeleton of the future preference Node + * + * Constructor. + */ + public PropertyLifecyclePreferencesManager() { + basicTabParentModels = new HashSet<StrategySet>(); + basicTabStrategiesIDs = new HashSet<String>(); + basicTabBrowsedModelsURI = new HashSet<String>(); + browseRegisteredPreferences(basicTabParentModels, basicTabStrategiesIDs, + basicTabBrowsedModelsURI, Messages.BasicBrowsedModels_Node, Messages.BasicSelectedStrategies_Node); + + advancedTabParentModels = new HashSet<StrategySet>(); + advancedTabStrategiesIDs = new HashSet<String>(); + advancedTabBrowsedModelsURI = new HashSet<String>(); + browseRegisteredPreferences(advancedTabParentModels, advancedTabStrategiesIDs, + advancedTabBrowsedModelsURI, Messages.AdvancedBrowsedModels_Node, Messages.AdvancedSelectedStrategies_Node); + } + + /** + * + * @return + * The strategies preferences + */ + public Preferences getRenamePreferences() { + return propertyLifecyclePreferences; + } + + /** + * Parse the current preference Node and retrieve the associated informations on the models and their strategies + * + * @param parentModels + * The current models + * @param strategiesIDs + * The current strategies IDs + * @param browsedModelsURI + * The current models' URis + * @param modelNodePath + * The model node to parse + * @param strategiesNodePath + * The strategy node to parse + */ + private void browseRegisteredPreferences(HashSet<StrategySet> parentModels, HashSet<String> strategiesIDs, + HashSet<String> browsedModelsURI, String modelNodePath, String strategiesNodePath) { + + try { + for (String childName : propertyLifecyclePreferences.childrenNames()) { + Preferences childNode = propertyLifecyclePreferences.node(childName); + if (childName.equalsIgnoreCase(modelNodePath)) { + for (String modelURI : childNode.keys()) { + browsedModelsURI.add(modelURI); + StrategySet model = BrowserUtils.getStrategySet(modelURI); + if (model != null) { + parentModels.add(model); + } + } + } + + if (childName.equalsIgnoreCase(strategiesNodePath)) { + for (String strategyID : childNode.keys()) { + strategiesIDs.add(strategyID); + } + } + + } + } catch (BackingStoreException bse) { + Activator.log.error(bse); + } + } + + /** + * Retrieve the strategy corresponding to an ID from the selected models + * + * @param strategyID + * The unique ID + * @param parentModels + * The selected models + * @param strategies + * The set containing the newly found pair + */ + private void getCorrespondigStrategy(String strategyID, HashSet<StrategySet> parentModels, + HashMap<String, StrategyElement> strategies) { + for (StrategySet model : parentModels) { + for (StrategyElement strategy : model.getStrategies()) { + if (strategyID.equals(strategy.getId())) { + strategies.put(strategyID, strategy); + } + } + } + } + + /** + * @return + * The strategies from the basic tab + */ + public Collection<StrategyElement> retrieveBasicTabStrategies() { + basicTabStrategies = new HashMap<String, StrategyElement>(); + basicTabStrategiesIDs = new HashSet<String>(); + basicTabBrowsedModelsURI = new HashSet<String>(); + basicTabParentModels = new HashSet<StrategySet>(); + + browseRegisteredPreferences(basicTabParentModels, basicTabStrategiesIDs, + basicTabBrowsedModelsURI, Messages.BasicBrowsedModels_Node, Messages.BasicSelectedStrategies_Node); + + for (String strategyID : basicTabStrategiesIDs) { + getCorrespondigStrategy(strategyID, basicTabParentModels, basicTabStrategies); + } + + // Activator.log.trace(Activator.RENAMING_PREFERENCES_TRACE, "basicTabStrategies.values(): " + basicTabStrategies.values().size()); + return basicTabStrategies.values(); + } + + /** + * @return + * The models' URI + */ + public Collection<String> retrieveBasicTabModelPaths() { + return basicTabBrowsedModelsURI; + } + + /** + * @return + * The strategies from the advanced tab + */ + public Collection<StrategyElement> retrieveAdvancedTabStrategies() { + advancedTabStrategies = new HashMap<String, StrategyElement>(); + advancedTabStrategiesIDs = new HashSet<String>(); + advancedTabBrowsedModelsURI = new HashSet<String>(); + advancedTabParentModels = new HashSet<StrategySet>(); + + browseRegisteredPreferences(advancedTabParentModels, advancedTabStrategiesIDs, + advancedTabBrowsedModelsURI, Messages.AdvancedBrowsedModels_Node, Messages.AdvancedSelectedStrategies_Node); + + for (String strategyID : advancedTabStrategiesIDs) { + getCorrespondigStrategy(strategyID, advancedTabParentModels, advancedTabStrategies); + } + + // Activator.log.trace(Activator.RENAMING_PREFERENCES_TRACE, "advancedTabStrategies.values(): " + advancedTabStrategies.values().size()); + return advancedTabStrategies.values(); + } + + /** + * @return + * All the strategies from the preference node and the selected strategies from both tabs + */ + public Collection<StrategyElement> retrieveAllStrategies() { + Map<String, StrategyElement> allStrategies = new HashMap<>(); + try { + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, "childrenNodes: " + propertyLifecyclePreferences.childrenNames().length); + if (propertyLifecyclePreferences.childrenNames().length == 0) { + // The User still hasn't selected anything in the preference page + // Populate the preferences with the default models + Map<String, StrategySet> renameSets = StrategySetRegistry.getInstance().getStrategySets(); + if (renameSets != null) { + for (String setKey : renameSets.keySet()) { + StrategySet renameSetConfiguration = renameSets.get(setKey); + String modelURI = renameSetConfiguration.eResource().getURI().toString(); + // Activator.log.trace(Activator.RENAMING_PREFERENCES_TRACE, "modelURI: " + modelURI); + + Preferences basicModelNode = propertyLifecyclePreferences.node(Messages.BasicBrowsedModels_Node); + basicModelNode.putBoolean(modelURI, true); + Preferences basicConfigurationNode = propertyLifecyclePreferences.node(Messages.BasicSelectedStrategies_Node); + for (StrategyElement configuration : renameSetConfiguration.getStrategies()) { + basicConfigurationNode.putBoolean(configuration.getId(), true); + } + } + } + + savePreferences(); + } + } catch (BackingStoreException e) { + Activator.log.error(e); + } + + // Get the preferences selected by the user + for (StrategyElement strategy : retrieveBasicTabStrategies()) { + allStrategies.put(strategy.getId(), strategy); + } + for (StrategyElement strategy : retrieveAdvancedTabStrategies()) { + allStrategies.put(strategy.getId(), strategy); + } + + Activator.log.trace(Activator.STRATEGY_PREFERENCES_TRACE, "allStrategies.size(): " + allStrategies.values().size()); + return allStrategies.values(); + } + + /** + * @return + * The models' URI + */ + public Collection<String> retrieveAdvancedTabModelPaths() { + return advancedTabBrowsedModelsURI; + } + + /** + * Register the selected strategies and their models in the preference node + * + * @param basicModelsURIs + * {@link #retrieveBasicTabModelPaths() retieveBasicTabModelPaths()} + * @param advancedModelsURIs + * {@link #retrieveAdvancedTabModelPaths() retieveAdvancedTabModelPaths()} + * @param basicConfigurations + * {@link #retrieveBasicTabStrategies() retrieveBasicTabStrategies()} + * @param advancedConfigurations + * {@link #retrieveAdvancedTabStrategies() retrieveAdvancedTabStrategies()} + */ + public void registerCurrentPreferences(Collection<String> basicModelsURIs, Collection<String> advancedModelsURIs, + Collection<StrategyElement> basicConfigurations, Collection<StrategyElement> advancedConfigurations) { + + clearPreferences(); + // Create the Nodes to house the preferences + Preferences basicModelNode = propertyLifecyclePreferences.node(Messages.BasicBrowsedModels_Node); + Preferences basicConfigurationNode = propertyLifecyclePreferences.node(Messages.BasicSelectedStrategies_Node); + Preferences advancedModelNode = propertyLifecyclePreferences.node(Messages.AdvancedBrowsedModels_Node); + Preferences advancedConfigurationNode = propertyLifecyclePreferences.node(Messages.AdvancedSelectedStrategies_Node); + + // Save all the models (URIs) used to get the current configuration + if (basicModelsURIs != null) { + for (String modelURI : basicModelsURIs) { + basicModelNode.putBoolean(modelURI, true); + } + } + if (advancedModelsURIs != null) { + for (String modelURI : advancedModelsURIs) { + advancedModelNode.putBoolean(modelURI, true); + } + } + + // Save all the strategies (IDs) used in the current configuration + if (basicConfigurations != null) { + for (StrategyElement strategy : basicConfigurations) { + basicConfigurationNode.putBoolean(strategy.getId(), true); + } + + } + if (advancedConfigurations != null) { + for (StrategyElement strategy : advancedConfigurations) { + advancedConfigurationNode.putBoolean(strategy.getId(), true); + } + } + + savePreferences(); + } + + /** + * Clear the preference node completely + */ + public void clearPreferences() { + try { + // Deletes all the preference's children nodes + String[] childrenNames = propertyLifecyclePreferences.childrenNames(); + for (String childName : childrenNames) { + Preferences childNode = propertyLifecyclePreferences.node(childName); + childNode.removeNode(); + } + + savePreferences(); + } catch (BackingStoreException e) { + Activator.log.error(e); + } + } + + /** + * Save the amended preference node + */ + private void savePreferences() { + try { + // Save the current strategies model's informations + propertyLifecyclePreferences.flush(); + } catch (BackingStoreException e) { + Activator.log.error(e); + } + } + + /** + * Verify that the node exists + * + * @param pathName + * The node's name + * @return + * true or false + */ + public boolean nodeExists(String pathName) { + try { + return propertyLifecyclePreferences.nodeExists(pathName); + } catch (BackingStoreException e) { + Activator.log.error(e); + } + return false; + } + +} diff --git a/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/SaveButton.java b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/SaveButton.java new file mode 100755 index 00000000000..327e0fd1c38 --- /dev/null +++ b/extraplugins/propertylifecycle/org.eclipse.papyrus.propertylifecycle.preferences/src/org/eclipse/papyrus/propertylifecycle/preferences/utils/SaveButton.java @@ -0,0 +1,140 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.propertylifecycle.preferences.utils; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +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.xmi.XMIResource; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.papyrus.propertylifecycle.preferences.Activator; +import org.eclipse.papyrus.propertylifecycle.preferences.messages.Messages; +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.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; + + +/** + * Class used to create the saver button, for the custom model in the advanced selection window, and its associated window + * + */ +public class SaveButton { + + private Composite parent; + + private TreeViewer parentViewer; + + public SaveButton(Composite parent, TreeViewer parentViewer) { + this.parent = parent; + this.parentViewer = parentViewer; + + createSaverButton(this.parent); + } + + /** + * Create a button that can be used to save the currently selected strategies as a new @see org.eclipse.emf.ecore.resource.Resource + * + * @param parent + * The parent Composite containing the button + */ + protected void createSaverButton(Composite parent) { + Button saveButton = new Button(parent, SWT.NONE); + saveButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + saveButton.setText(Messages.SaveButton_Label); + + saveButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // Initialize the default variable + saveModelResource(Messages.CustomModel_DefaultName); + } + }); + } + + /** + * Save the strategies inside a new @see org.eclipse.emf.ecore.resource.Resource + */ + private void saveModelResource(String modelName) { + FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE); + dialog.setText(Messages.SystemSaveDialog_Title); + // String filterPath = "/"; + // String platform = SWT.getPlatform(); + // if (platform.equals("win32")) { + // filterPath = "c:\\"; + // } + + // ConvertEcoreToUML convertDialog = new ConvertEcoreToUML(); + // convertDialog.run(new Action() { + // }); + + String[] filterExtensions = { "*.propertylifecycle" }; //$NON-NLS-1$ + String[] filterExtensionsNames = { "Strategies Models" }; //$NON-NLS-1$ + dialog.setFilterNames(filterExtensionsNames); + dialog.setFilterExtensions(filterExtensions); + // dialog.setFilterPath(filterPath); + dialog.setFileName(modelName); + + String dialogResult = dialog.open(); + if (dialogResult == null) { + return; + } + + Resource resource = getViewerModel(); + if (resource == null) { + return; + } + + URI resourceURI = CommonPlugin.resolve(URI.createFileURI(dialogResult)); + // URI resourceURI = URI.createFileURI(dialogResult); + resource.setURI(resourceURI); + + try { + Map<Object, Object> options = new HashMap<Object, Object>(); + options.put(XMIResource.OPTION_ENCODING, getEncoding()); + resource.save(options); + } catch (IOException e) { + // TODO display an error message in the preference window + Activator.log.error(e); + } + } + + public Resource getViewerModel() { + Object viewerInput = parentViewer.getInput(); + if (viewerInput != null && viewerInput instanceof ResourceSet) { + return ((ResourceSet) viewerInput).getResources().get(0); + } + + return null; + } + + /** + * The encoding used for the file + * + * @return + * UTF-8 + */ + public String getEncoding() { + return "UTF-8"; //$NON-NLS-1$ + } + +} |