diff options
Diffstat (limited to 'plugins/org.eclipse.emf.compare.mpatch.apply')
29 files changed, 0 insertions, 3664 deletions
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/.classpath b/plugins/org.eclipse.emf.compare.mpatch.apply/.classpath deleted file mode 100644 index 2d1a4302f..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?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/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/.project b/plugins/org.eclipse.emf.compare.mpatch.apply/.project deleted file mode 100644 index 27a0dd740..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.emf.compare.mpatch.apply</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/plugins/org.eclipse.emf.compare.mpatch.apply/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.emf.compare.mpatch.apply/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index e8df766e2..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,77 +0,0 @@ -#Thu Oct 27 12:55:55 CEST 2011
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
-org.eclipse.jdt.core.compiler.problem.comparingIdentical=error
-org.eclipse.jdt.core.compiler.problem.deadCode=error
-org.eclipse.jdt.core.compiler.problem.deprecation=warning
-org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled
-org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
-org.eclipse.jdt.core.compiler.problem.discouragedReference=error
-org.eclipse.jdt.core.compiler.problem.emptyStatement=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
-org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
-org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
-org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
-org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
-org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error
-org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
-org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
-org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=error
-org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error
-org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
-org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error
-org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error
-org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
-org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error
-org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
-org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
-org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
-org.eclipse.jdt.core.compiler.problem.nullReference=error
-org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
-org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning
-org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
-org.eclipse.jdt.core.compiler.problem.potentialNullReference=error
-org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
-org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
-org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
-org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=enabled
-org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error
-org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
-org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
-org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning
-org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
-org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
-org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
-org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=error
-org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
-org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
-org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
-org.eclipse.jdt.core.compiler.problem.unusedImport=warning
-org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
-org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
-org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
-org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
-org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=disabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
-org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
-org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error
-org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.mpatch.apply/META-INF/MANIFEST.MF deleted file mode 100644 index ceb92c524..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/META-INF/MANIFEST.MF +++ /dev/null @@ -1,18 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.emf.compare.mpatch.apply;singleton:=true -Bundle-Version: 1.3.0.qualifier -Bundle-Activator: org.eclipse.emf.compare.mpatch.apply.ApplyActivator -Require-Bundle: org.eclipse.compare, - org.eclipse.ui.ide, - org.eclipse.emf.compare.mpatch.edit;visibility:=reexport, - org.eclipse.emf.compare.diff;visibility:=reexport, - org.eclipse.emf.compare.ui, - org.eclipse.emf.ecore.xmi, - org.eclipse.emf.compare.mpatch.common;visibility:=reexport -Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.eclipse.emf.compare.mpatch.apply.util -Bundle-Vendor: %providerName -Bundle-Localization: plugin diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/about.html b/plugins/org.eclipse.emf.compare.mpatch.apply/about.html deleted file mode 100644 index 670d10856..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/about.html +++ /dev/null @@ -1,106 +0,0 @@ -<!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>Eclipse Foundation Software User Agreement</title> -</head> - -<body lang="EN-US"> -<h2>Eclipse Foundation Software User Agreement</h2> -<p>April 14, 2010</p> - -<h3>Usage Of Content</h3> - -<p>THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS - (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND - CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE - OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR - NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND - CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.</p> - -<h3>Applicable Licenses</h3> - -<p>Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 - ("EPL"). A copy of the EPL is provided with this Content and is also 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>Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code - repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").</p> - -<ul> - <li>Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").</li> - <li>Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".</li> - <li>A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins - and/or Fragments associated with that Feature.</li> - <li>Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.</li> -</ul> - -<p>The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and -Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module -including, but not limited to the following locations:</p> - -<ul> - <li>The top-level (root) directory</li> - <li>Plug-in and Fragment directories</li> - <li>Inside Plug-ins and Fragments packaged as JARs</li> - <li>Sub-directories of the directory named "src" of certain Plug-ins</li> - <li>Feature directories</li> -</ul> - -<p>Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the -installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or -inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature. -Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in -that directory.</p> - -<p>THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE -OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):</p> - -<ul> - <li>Common Public License Version 1.0 (available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>)</li> - <li>Apache Software License 1.1 (available at <a href="http://www.apache.org/licenses/LICENSE">http://www.apache.org/licenses/LICENSE</a>)</li> - <li>Apache Software License 2.0 (available at <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)</li> - <li>Metro Link Public License 1.00 (available at <a href="http://www.opengroup.org/openmotif/supporters/metrolink/license.html">http://www.opengroup.org/openmotif/supporters/metrolink/license.html</a>)</li> - <li>Mozilla Public License Version 1.1 (available at <a href="http://www.mozilla.org/MPL/MPL-1.1.html">http://www.mozilla.org/MPL/MPL-1.1.html</a>)</li> -</ul> - -<p>IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please -contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.</p> - - -<h3>Use of Provisioning Technology</h3> - -<p>The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse - Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or - other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to - install, extend and update Eclipse-based products. Information about packaging Installable Software is available at <a - href="http://eclipse.org/equinox/p2/repository_packaging.html">http://eclipse.org/equinox/p2/repository_packaging.html</a> - ("Specification").</p> - -<p>You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the - applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology - in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the - Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:</p> - -<ol> - <li>A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology - on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based - product.</li> - <li>During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be - accessed and copied to the Target Machine.</li> - <li>Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable - Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target - Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern - the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such - indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.</li> -</ol> - -<h3>Cryptography</h3> - -<p>Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to - another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import, - possession, or use, and re-export of encryption software, to see if this is permitted.</p> - -<p><small>Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.</small></p> -</body> -</html>
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/build.properties b/plugins/org.eclipse.emf.compare.mpatch.apply/build.properties deleted file mode 100644 index d59a11864..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/build.properties +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2010, 2011 Technical University of Denmark.
-# 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:
-# Patrick Koenemann, DTU Informatics - initial API and implementation
-
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- plugin.xml,\
- icons/mpatch.gif,\
- icons/diff_80.gif,\
- icons/diff_48.gif,\
- icons/diff_32.gif,\
- icons/diff_16.gif,\
- about.html,\
- plugin.properties
-src.includes = about.html
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/_readme.txt b/plugins/org.eclipse.emf.compare.mpatch.apply/icons/_readme.txt deleted file mode 100644 index 778eec48b..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/_readme.txt +++ /dev/null @@ -1 +0,0 @@ -copied from org.eclipse.emf.compare.mpatch.emfdiff2mpatch/icons
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_16.gif b/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_16.gif Binary files differdeleted file mode 100644 index ff582ef15..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_16.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_32.gif b/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_32.gif Binary files differdeleted file mode 100644 index 30e64a1c2..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_32.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_48.gif b/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_48.gif Binary files differdeleted file mode 100644 index 0fc886959..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_48.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_80.gif b/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_80.gif Binary files differdeleted file mode 100644 index b8fc42c57..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/diff_80.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/mpatch.gif b/plugins/org.eclipse.emf.compare.mpatch.apply/icons/mpatch.gif Binary files differdeleted file mode 100644 index 1c6e0f613..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/icons/mpatch.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/plugin.properties b/plugins/org.eclipse.emf.compare.mpatch.apply/plugin.properties deleted file mode 100644 index 778f81290..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/plugin.properties +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2010, 2011 Technical University of Denmark.
-# 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:
-# Patrick Koenemann, DTU Informatics - initial API and implementation
-#
-# $Id: plugin.properties,v 1.1 2010/09/10 15:23:08 cbrun Exp $
-
-pluginName = MPatch Application Plugin
-providerName = Eclipse Modeling Project
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/plugin.xml b/plugins/org.eclipse.emf.compare.mpatch.apply/plugin.xml deleted file mode 100644 index 0f27dd995..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/plugin.xml +++ /dev/null @@ -1,87 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.4"?> -<!-- - Copyright (c) 2010, 2011 Technical University of Denmark. - 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: - Patrick Koenemann, DTU Informatics - initial API and implementation ---> -<plugin> - <extension - point="org.eclipse.ui.popupMenus"> - <objectContribution - id="org.eclipse.emf.compare.mpatch.apply.startapply" - nameFilter="*mpatch" - objectClass="org.eclipse.core.resources.IFile"> - <action - class="org.eclipse.emf.compare.mpatch.apply.actions.ApplyAction" - enablesFor="1" - id="org.eclipse.emf.compare.mpatch.apply.ApplyAction" - label="Apply MPatch" - menubarPath="org.eclipse.emf.compare.mpatch.mpatchmenu/apply"> - </action> - <menu - icon="icons/diff_16.gif" - id="org.eclipse.emf.compare.mpatch.mpatchmenu" - label="MPatch" - path="additions"> - </menu> - </objectContribution> - </extension> - <!-- PK: deactivated for contribution because it is too intrusive. - discussion at: https://bugs.eclipse.org/bugs/show_bug.cgi?id=297812 - -> - <extension - point="org.eclipse.ui.popupMenus"> - <objectContribution - id="org.eclipse.emf.compare.mpatch.apply.startapply2" - nameFilter="*" - objectClass="org.eclipse.core.resources.IFile"> - <action - class="org.eclipse.emf.compare.mpatch.apply.actions.ApplyAction" - enablesFor="2" - id="org.eclipse.emf.compare.mpatch.apply.ApplyAction2" - label="Apply MPatch" - menubarPath="org.eclipse.emf.compare.mpatch.mpatchmenu/apply"> - </action> - <menu - icon="icons/diff_16.gif" - id="org.eclipse.emf.compare.mpatch.mpatchmenu" - label="MPatch" - path="additions"> - </menu> - </objectContribution> - </extension> - <!- - --> -<extension - point = "org.eclipse.ui.newWizards"> - <wizard - category="org.eclipse.emf.compare.mpatch.Wizard.ID" - id="org.eclipse.emf.compare.mpatch.apply.applywizard" - name="Apply MPatch" - class="org.eclipse.emf.compare.mpatch.apply.wizards.ApplyWizard" - icon="icons/diff_16.gif"> - <description>Apply MPatch to another model</description> - <selection class="org.eclipse.core.resources.IResource" /> - </wizard> -</extension> - <extension - point="org.eclipse.ui.editorActions"> - <editorContribution - id="org.eclipse.emf.compare.mpatch.apply.mpatcheditor" - targetID="org.eclipse.emf.compare.mpatch.presentation.mpatchEditorID"> - <action - class="org.eclipse.emf.compare.mpatch.apply.actions.ApplyAction" - icon="icons/diff_16.gif" - id="org.eclipse.emf.compare.mpatch.apply.actions.ApplyAction3" - label="Apply MPatch" - style="push" - toolbarPath="additions" - tooltip="Open the wizard for applying this MPatch to a model"> - </action> - </editorContribution> - </extension> -</plugin> diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/pom.xml b/plugins/org.eclipse.emf.compare.mpatch.apply/pom.xml deleted file mode 100644 index 9d6293b15..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>emf.compare-parent</artifactId> - <groupId>org.eclipse.emf.compare</groupId> - <version>1.3.0-SNAPSHOT</version> - <relativePath>../..</relativePath> - </parent> - <groupId>org.eclipse.emf.compare</groupId> - <artifactId>org.eclipse.emf.compare.mpatch.apply</artifactId> - <version>1.3.0-SNAPSHOT</version> - <packaging>eclipse-plugin</packaging> - - <build> - <plugins> - <plugin> - <groupId>org.eclipse.tycho</groupId> - <artifactId>tycho-source-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/ApplyActivator.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/ApplyActivator.java deleted file mode 100644 index 344cccf4e..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/ApplyActivator.java +++ /dev/null @@ -1,104 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- */
-public class ApplyActivator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.emf.compare.mpatch.apply";
-
- // The shared instance
- private static ApplyActivator plugin;
-
- /**
- * The constructor
- */
- public ApplyActivator() {
- // Nothing to do
- }
-
- /*
- * (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;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static ApplyActivator getDefault() {
- return plugin;
- }
-
- // //////////// SOME LOGGING
-
- public void logError(String error) {
- logError(error, null);
- }
-
- public void logError(String error, Throwable throwable) {
- if (error == null && throwable != null) {
- error = throwable.getMessage();
- }
- getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, error, throwable));
- debug(error, throwable);
- }
-
- public void logInfo(String message) {
- logInfo(message, null);
- }
-
- public void logInfo(String message, Throwable throwable) {
- if (message == null && throwable != null) {
- message = throwable.getMessage();
- }
- getLog().log(new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK, message, throwable));
- debug(message, throwable);
- }
-
- private void debug(String message, Throwable throwable) {
- if (!isDebugging()) {
- return;
- }
- if (message != null) {
- System.err.println(message);
- }
- if (throwable != null) {
- throwable.printStackTrace();
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/actions/ApplyAction.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/actions/ApplyAction.java deleted file mode 100644 index 674b30e87..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/actions/ApplyAction.java +++ /dev/null @@ -1,138 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply.actions;
-
-import java.util.Iterator;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.mpatch.MPatchModel;
-import org.eclipse.emf.compare.mpatch.apply.wizards.ApplyWizard;
-import org.eclipse.emf.compare.mpatch.common.util.CommonUtils;
-import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorActionDelegate;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPart;
-
-/**
- * An action which checks the currently selected element for an {@link MPatchModel} and launches the wizard for applying
- * it to another model.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- *
- */
-public class ApplyAction implements IObjectActionDelegate, IEditorActionDelegate {
-
- /** Store the selection. */
- private IStructuredSelection selection;
-
- /** The shell. */
- private Shell shell;
-
- /** Store it because we need it to launch the wizard. */
- private IWorkbench workbench;
-
- /**
- * This action simply takes the current selection and opens the wizard {@link ApplyWizard} with it.
- */
- public void run(IAction action) {
- // Create the wizard
- final ApplyWizard wizard = new ApplyWizard();
- wizard.init(workbench, selection);
-
- // Create the wizard dialog
- final WizardDialog dialog = new WizardDialog(shell, wizard);
- // Open the wizard dialog
- dialog.open();
- }
-
- /**
- * Enable action depending on the selection.
- */
- public void selectionChanged(IAction action, ISelection selection) {
- this.selection = null;
- if (selection instanceof IStructuredSelection) {
- final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- if (structuredSelection.size() == 1 || structuredSelection.size() == 2) {
- for (Iterator<?> i = structuredSelection.iterator(); i.hasNext();) {
- final Object obj = (Object) i.next();
- if (obj instanceof IFile) {
- final IFile file = (IFile) obj;
- if (MPatchConstants.FILE_EXTENSION_MPATCH.equals(file.getFileExtension())) {
- this.selection = structuredSelection;
- return;
- }
- } else if (obj instanceof EObject) {
- final EObject root = EcoreUtil.getRootContainer((EObject) obj);
- if (root instanceof MPatchModel && root.eResource() != null) {
- final IFile file = getFileFromResource(root.eResource());
- if (file != null) {
- this.selection = new StructuredSelection(file);
- }
- }
- } else if (obj instanceof Resource) {
- final IFile file = getFileFromResource((Resource)obj);
- if (file != null) {
- this.selection = new StructuredSelection(file);
- }
- }
- }
- }
- }
- action.setEnabled(this.selection != null);
- }
-
- private static IFile getFileFromResource(Resource obj) {
- final URI uri = obj.getURI();
- final IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();
- final String[] segments = uri.segments();
- if (segments != null && segments.length > 1) {
- final String[] newSegments = new String[segments.length - 1];
- System.arraycopy(segments, 1, newSegments, 0, newSegments.length);
- final IPath path = new Path("/" + CommonUtils.join(newSegments, "/"));
- final IFile file = ws.getFile(path);
- if (file != null && file.exists()) {
- return file;
- }
- }
- return null;
- }
-
- /**
- * Get Shell and workbench.
- */
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- shell = targetPart.getSite().getShell();
- workbench = targetPart.getSite().getWorkbenchWindow().getWorkbench();
- }
-
- public void setActiveEditor(IAction action, IEditorPart targetEditor) {
- if (targetEditor != null) {
- shell = targetEditor.getSite().getShell();
- workbench = targetEditor.getSite().getWorkbenchWindow().getWorkbench();
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/MPatchResolver.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/MPatchResolver.java deleted file mode 100644 index d5c375ae1..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/MPatchResolver.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.compare.mpatch.ChangeGroup; -import org.eclipse.emf.compare.mpatch.IElementReference; -import org.eclipse.emf.compare.mpatch.IndepAddElementChange; -import org.eclipse.emf.compare.mpatch.IndepChange; -import org.eclipse.emf.compare.mpatch.MPatchModel; -import org.eclipse.emf.compare.mpatch.MPatchPackage; -import org.eclipse.emf.compare.mpatch.UnknownChange; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences.ValidationResult; -import org.eclipse.emf.compare.mpatch.util.ExtEcoreUtils; -import org.eclipse.emf.compare.mpatch.util.MPatchUtil; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.resource.Resource; - -/** - * A helper class for resolving all symbolic references of the given differences for the given model. The result is an - * instance of {@link ResolvedSymbolicReferences} which contains a raw symbolic reference resolution and a resolution - * grouped per {@link IndepChange}. - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ -public class MPatchResolver { - - /** A constant defining the resolution of elements in the unchanged model of an mpatch. */ - public static final int RESOLVE_UNCHANGED = ResolvedSymbolicReferences.RESOLVE_UNCHANGED; - - /** A constant defining the resolution of elements in the changed model of an mpatch. */ - public static final int RESOLVE_CHANGED = ResolvedSymbolicReferences.RESOLVE_CHANGED; - - /** - * This resolves all symbolic references and wraps it in a result object of type {@link ResolvedSymbolicReferences} - * . It usually makes use of {@link MPatchResolver#resolveSymbolicReferences(MPatchModel, Resource)}.<br> - * <br> - * Since the diff is not directed, the symbolic references can be resolved either for the target (right) or the - * source (left) model. This is given in the parameter <code>direction</code>.<br> - * <br> - * <b>Please note: Quite often a symbolic reference is resolved to too many model elements! That can - * - * @param mpatch - * An mpatch. - * @param model - * An emf model for which the symbolic references should be resolved. <b>Note that its meta model should - * rather be the same as the one of the originating models the diff was created from!</b> - * @param direction - * The direction for symbolic reference resolution. Either {@link MPatchResolver#RESOLVE_UNCHANGED} - * (resolves the elements <i>before</i> the change) or {@link MPatchResolver#RESOLVE_CHANGED} (resolves - * the elements <i>after</i> the change). - * @return A wrapper element for the result, see {@link ResolvedSymbolicReferences} for details. - */ - public static ResolvedSymbolicReferences resolveSymbolicReferences(final MPatchModel mpatch, final EObject model, - final int direction, boolean respectApplied) { - // 0. prepare result - final Map<IElementReference, List<EObject>> rawResult = new HashMap<IElementReference, List<EObject>>(); - final Map<IndepChange, Map<IElementReference, List<EObject>>> resolution = new LinkedHashMap<IndepChange, Map<IElementReference, List<EObject>>>(); - final Map<IElementReference, List<IElementReference>> equalRefs = new LinkedHashMap<IElementReference, List<IElementReference>>(); - final Map<IndepChange, ValidationResult> validation = new LinkedHashMap<IndepChange, ValidationResult>(); - final ResolvedSymbolicReferences result = new ResolvedSymbolicReferences(mpatch, model, direction, resolution, - rawResult, equalRefs, validation); - - // 1. resolve all (!) symbolic references - resolveRawSymbolicReferences(result); - - // 2. prepare and fill result - for (final IndepChange change : mpatch.getChanges()) { - analyzeChange(change, rawResult, direction, resolution); - } - - // 3. remove invalid states! - final boolean forward = direction == ResolvedSymbolicReferences.RESOLVE_UNCHANGED; - final List<IndepChange> orderedChanges = MPatchValidator.orderChanges(result.getResolutionByChange().keySet(), forward); - for (IndepChange change : orderedChanges) { - checkStateResolution(change, result, false, forward, respectApplied); - } - - // 4. return wrapper object - return result; - } - - /** - * Resolve symbolic references <b>in a raw form</b>. This means that all symbolic references (instances of - * {@link IElementReference}) are collected from the input diff ({@link MPatchModel}) and resolved for the given - * resource. The collection is then returned in a map.<br> - * <br> - * <b>Note: If you need symbolic reference resolution depending on the direction, you should rather use - * {@link IDiffApplier#resolveSymbolicReferences(MPatchModel, Resource, int)}, because it makes use of this - * method.</b> - * - * A mapping from symbolic references to all resolved model elements is stored in - * {@link ResolvedSymbolicReferences#getRawResolution()}. - * - * @param result - * The data object containing references to an mpatch and a model for which the symbolic references - * should be resolved. <b>Note that its meta model should rather be the same as the one of the - * originating models the diff was created from!</b> - */ - protected static void resolveRawSymbolicReferences(final ResolvedSymbolicReferences result) { - // 1. collect all symbolic references - final List<EObject> references = ExtEcoreUtils.collectTypedElements(result.getMPatchModel().getChanges(), - Collections.singleton(MPatchPackage.Literals.IELEMENT_REFERENCE), true); - - // 2. iterate over all symbolic references and try to resolve them - for (final EObject obj : references) { - final IElementReference ref = (IElementReference) obj; - - // 3. check if there is an equally resolving symref - List<EObject> resolution = null; - final Map<IElementReference, List<IElementReference>> equallyResolvingRefs = result - .getEquallyResolvingReferences(); - for (IElementReference ref2 : equallyResolvingRefs.keySet()) { - if (ref.resolvesEqual(ref2)) { - - // if so, add current ref to existing collection - MPatchUtil.addElementToListMap(ref2, ref, equallyResolvingRefs); - - // add ref as new key - equallyResolvingRefs.put(ref, equallyResolvingRefs.get(ref2)); - - // clone existing resolution - resolution = new ArrayList<EObject>(result.getRawResolution().get(ref2)); - break; - } - } - - // resolve and create new collection only if not resolved before! - if (resolution == null) { - resolution = ref.resolve(result.getModel()); // the actual reference resolution! - MPatchUtil.addElementToListMap(ref, ref, equallyResolvingRefs); // new collection - } - - // add resolution to result - result.getRawResolution().put(ref, resolution); - } - } - - /** - * Convert raw result into a more convenient format. - */ - protected static void analyzeChange(final IndepChange change, - final Map<IElementReference, List<EObject>> rawResult, final int direction, - final Map<IndepChange, Map<IElementReference, List<EObject>>> accumulator) { - if (change instanceof ChangeGroup) { - - // recursive call for groups - final ChangeGroup group = (ChangeGroup) change; - for (final IndepChange subChange : group.getSubChanges()) { - analyzeChange(subChange, rawResult, direction, accumulator); - } - // TODO: we skip corresponding elements for groups here! maybe we need that later?! - - } else if (!(change instanceof UnknownChange)) { - - // fill map only for the relevant references, depending on the direction - final Map<IElementReference, List<EObject>> map = new HashMap<IElementReference, List<EObject>>(); - - // regular symrefs - final Collection<EReference> importantRefs = MPatchValidator.getImportantReferencesFor(change.eClass(), - direction); - for (final EReference ref : importantRefs) { - final IElementReference symRef = (IElementReference) change.eGet(ref); - if (symRef != null) - map.put(symRef, rawResult.get(symRef)); - } - - // cross reference symrefs - final Map<IElementReference, IndepChange> crossRefs = MPatchUtil.collectCrossReferences(Collections - .singletonList(change)); - for (final IElementReference symRef : crossRefs.keySet()) { - if (symRef != null && !map.containsKey(symRef)) - map.put(symRef, rawResult.get(symRef)); - } - - // store that to the accumulator - accumulator.put(change, map); - } - } - - /** - * Check the state of the given change. If it is only partially valid, remove all invalid corresponding elements. If - * it cannot be validated at all, return false. - * - * @param change - * The change to check. - * @param mapping - * The resolution of all changes. - * @param reduce - * If <code>true</code>, then the resolutions might be reduced to the maximum number of allowed elements - * as defined by the upper bound. However, it might remove good matches, too! - * @param forward - * The direction of resolution. - * @return <code>true</code>, if the state is valid or could be fixed. <code>false</code> if the state could not be - * fixed. - */ - public static boolean checkStateResolution(IndepChange change, ResolvedSymbolicReferences mapping, - boolean reduce, boolean forward, boolean respectApplied) { - - final Map<IElementReference, List<EObject>> changeMapping = mapping.getResolutionByChange().get(change); - - final ValidationResult allValidStates = MPatchValidator.validateElementState(change, mapping, true, forward); - - switch (allValidStates) { - case STATE_BEFORE: - // cool, this one is fine! - - // maybe there are false additions we need to clean up? - if (change instanceof IndepAddElementChange) { - final List<EObject> resolvedAdditions = changeMapping.get(((IndepAddElementChange) change).getSubModelReference()); - if (resolvedAdditions != null && !resolvedAdditions.isEmpty()) { - resolvedAdditions.clear(); - } - } - return true; - - case STATE_AFTER: - // this one is only fine if we respect applied changes! - return respectApplied; - - case UNKNOWN_CHANGE: - // Oups.. where does that one come from?! anyway.. let's kick it out! - return false; - - case STATE_INVALID: - // ok, this one needs further investigation. maybe we can validate it by removing some corresponding - // elements! Lets check that: - if (changeMapping.get(change.getCorrespondingElement()).size() <= 1) - return false; // we cannot do much if there is just one element with an invalid state! - final ValidationResult anyValidState = MPatchValidator.validateElementState(change, mapping, false, - forward); - if (ValidationResult.STATE_BEFORE.equals(anyValidState) || ValidationResult.STATE_AFTER.equals(anyValidState)) { - return filterValidStates(change, mapping, change.getCorrespondingElement().getUpperBound(), reduce, forward); - } - return false; // if there is not even one valid state (strict was false!), we cannot do much... - - case REFERENCE: - // Some reference was not resolved successfully. We cannot do much here if it's not the corresponding - // element that failed. So let's check that! - final IElementReference symref = change.getCorrespondingElement(); - final List<EObject> elements = changeMapping.get(symref); - if (elements == null || elements.isEmpty()) - return false; // no resolution - not valid! - final boolean valid = MPatchValidator.validateResolution(symref, elements); - if (valid) - return false; // nope.. we cannot solve invalid cross references... - if (symref.getUpperBound() < elements.size() && elements.size() > 1) { - // ok, here we can do something! Let's just remove those whose states are invalid! - return filterValidStates(change, mapping, symref.getUpperBound(), reduce, forward); - } - return false; // I don't know how we could resolve the references now... kick it out! - - default: - throw new RuntimeException("Unknown status value received: " + allValidStates); - } - } - - /** - * Filter only those resolved corresponding elements whose state is valid. - * - * In case there are too many elements resolved, i.e. the number of resolved elements is greater than - * <code>maxElements</code>, then only the first <code>#maxElements</code> are used!!! <b>This is just a heuristic - * and might remove wanted and return unwanted elements!!! So the user should ALWAYS check the resolution - * manually!!!</b> - * - * @param change - * The change under investigation. - * @param mapping - * The resolution of all changes. - * @param maxElements - * The maximum number of resolved corresponding elements allowed. - * @param reduce - * If <code>true</code>, then the resolutions might be reduced to the maximum number of allowed elements - * as defined by <code>maxElements</code>. However, it might remove good matches, too! - * @param forward - * The direction of resolution. - * @return <code>true</code> if the resolution could be fixed for the given conditions, <code>false</code> - * otherwise. - */ - private static boolean filterValidStates(IndepChange change, ResolvedSymbolicReferences mapping, - int maxElements, boolean reduce, boolean forward) { - - final Map<IElementReference, List<EObject>> changeMapping = mapping.getResolutionByChange().get(change); - - // unfortunately, we don't have individual state testing opportunities, so we do that for each resolved - // corresponding element individually! - final List<EObject> resolvedElements = changeMapping.get(change.getCorrespondingElement()); - final List<EObject> allResolvedElements = new ArrayList<EObject>(resolvedElements); - final List<EObject> beforeElements = new ArrayList<EObject>(resolvedElements.size()); - final List<EObject> afterElements = new ArrayList<EObject>(resolvedElements.size()); - for (EObject element : allResolvedElements) { - resolvedElements.clear(); // let's clear it temporarily to test the current element - resolvedElements.add(element); - final ValidationResult state = MPatchValidator.validateElementState(change, mapping, true, forward); - if (ValidationResult.STATE_BEFORE.equals(state)) - beforeElements.add(element); - else if (ValidationResult.STATE_AFTER.equals(state)) - afterElements.add(element); - } - resolvedElements.clear(); - - // If we got valid elements with state BEFORE, let's use them! otherwise we use AFTER. - final List<EObject> validElements = beforeElements.isEmpty() ? afterElements : beforeElements; - - // now we filtered all valid elements! - // if there are too many, just get as much we need... - final int count = reduce ? Math.min(maxElements, validElements.size()) : validElements.size(); - for (int i = 0; i < count; i++) { - resolvedElements.add(validElements.get(i)); - } - - return !resolvedElements.isEmpty(); - } -} diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/MPatchValidator.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/MPatchValidator.java deleted file mode 100644 index 2b05d77f6..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/MPatchValidator.java +++ /dev/null @@ -1,914 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.compare.mpatch.IElementReference; -import org.eclipse.emf.compare.mpatch.IModelDescriptor; -import org.eclipse.emf.compare.mpatch.IndepAddAttributeChange; -import org.eclipse.emf.compare.mpatch.IndepAddElementChange; -import org.eclipse.emf.compare.mpatch.IndepAddReferenceChange; -import org.eclipse.emf.compare.mpatch.IndepAddRemAttributeChange; -import org.eclipse.emf.compare.mpatch.IndepAddRemElementChange; -import org.eclipse.emf.compare.mpatch.IndepAddRemReferenceChange; -import org.eclipse.emf.compare.mpatch.IndepChange; -import org.eclipse.emf.compare.mpatch.IndepMoveElementChange; -import org.eclipse.emf.compare.mpatch.IndepRemoveAttributeChange; -import org.eclipse.emf.compare.mpatch.IndepRemoveElementChange; -import org.eclipse.emf.compare.mpatch.IndepRemoveReferenceChange; -import org.eclipse.emf.compare.mpatch.IndepUpdateAttributeChange; -import org.eclipse.emf.compare.mpatch.IndepUpdateReferenceChange; -import org.eclipse.emf.compare.mpatch.MPatchModel; -import org.eclipse.emf.compare.mpatch.MPatchPackage; -import org.eclipse.emf.compare.mpatch.ModelDescriptorReference; -import org.eclipse.emf.compare.mpatch.UnknownChange; -import org.eclipse.emf.compare.mpatch.extension.IMPatchResolution; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences.ValidationResult; -import org.eclipse.emf.compare.mpatch.util.ExtEcoreUtils; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; - -/** - * Validator functions for the resolution of an ({@link MPatchModel}) to a target model. The resolution is initially - * created with {@link MPatchResolver} and stored in {@link ResolvedSymbolicReferences} . - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ -public final class MPatchValidator { - - /** - * Validate a resolution of symbolic references. It just calls - * {@link MPatchValidator#validateResolution(IElementReference, Collection)} for all symbolic references in - * {@link ResolvedSymbolicReferences#result()} and returns a collection of changes which did not resolve correctly. - * - * Note that {@link UnknownChange}s are not allowed at all! - * - * {@link ModelDescriptorReference}s are valid if the depending change is valid. - * - * @param mapping - * A mapping of resolved symbolic references to a model; typically created by {@link MPatchResolver} and - * maybe modified by {@link IMPatchResolution}. - * @param respectApplied - * Respect and bind changes that have already been applied to the model. - * @return A list of changes for which not all symbolic references were resolved successfully or the state before or - * after the change could not be found. - */ - public static List<IndepChange> validateResolutions(ResolvedSymbolicReferences mapping, boolean respectApplied) { - final Set<IndepChange> result = new HashSet<IndepChange>(); - - // update validation states! - validateElementStates(mapping, false); - - // iterate over all selected IndepChanges - for (IndepChange change : mapping.getResolutionByChange().keySet()) { - - // check state first - final ValidationResult valid = mapping.getValidation().get(change); - if (!ValidationResult.STATE_BEFORE.equals(valid) && !ValidationResult.STATE_AFTER.equals(valid)) { - result.add(change); - continue; - } - - // if applied changes are not ok.. - if (ValidationResult.STATE_AFTER.equals(valid) && !respectApplied) { - result.add(change); - continue; - } - - // make sure all changes the current change depends on are also validated! - if (!mapping.getResolutionByChange().keySet().containsAll(change.getDependsOn())) { - result.add(change); - } - } - - // iterate over all selected IndepChanges again to find violations of model descriptor references - for (IndepChange change : mapping.getResolutionByChange().keySet()) { - if (result.contains(change)) - continue; // already invalid! - - // iterate over all symbolic references of the current change - final Map<IElementReference, List<EObject>> symrefs = mapping.getResolutionByChange().get(change); - for (IElementReference ref : symrefs.keySet()) { - if (ref instanceof ModelDescriptorReference) { - - // special case: model descriptor references cannot be checked now - but change with model descriptor - // must be valid! - final IndepChange otherChange = (IndepChange) ExtEcoreUtils.getContainerOfType( - ((ModelDescriptorReference) ref).getResolvesTo(), - MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE); - if (result.contains(otherChange)) - result.add(change); - } - } - } - - return new ArrayList<IndepChange>(result); - } - - /** - * Check whether the given symbolic reference resolves the correct number of model elements. For most symbolic - * references, there must be exactly <i>one</i> element resolved. However, implementations may allow multiple - * elements to be resolved, stated by {@link IElementReference#getLowerBound()} and - * {@link IElementReference#getUpperBound()}. - * - * {@link ModelDescriptorReference}s have a special role because they are internal references. They are valid as - * long as the depending change is valid. - * - * @param ref - * A symbolic reference. - * @param elements - * The resolved elements for which the resolution is checked. - * @return <code>true</code>, if the cardinality matches the given elements, <code>false</code> otherwise. - */ - public static boolean validateResolution(IElementReference ref, Collection<EObject> elements) { - if (ref instanceof ModelDescriptorReference) - return true; // cannot be resolved for the time being - final int lowerBound = ref.getLowerBound(); - final int upperBound = ref.getUpperBound(); - if (elements == null) { - return false; // null is obviously not valid! - } else if (lowerBound < 0) { - return false; // lower bound must not be less than 0! - } else if (upperBound == lowerBound) { - return elements.size() == upperBound; // exact number of elements required - } else if (upperBound < 0) { - return lowerBound <= elements.size(); // at least lowerBounds - } else if (upperBound > lowerBound) { - return lowerBound <= elements.size() && upperBound >= elements.size(); // between lowerBound and upperBound - } else { - return false; // lower bound must not be higher than upper bound in all other cases! - } - } - - /** - * Check that all changes are resolved to the correct elements which represent either the state before or after the - * change. For example for an attribute change, check that the actual attribute exists having the value either - * before of after the change. - * - * The result is stored in {@link ResolvedSymbolicReferences#getValidation()}. - * - * Note that {@link UnknownChange}s are not allowed at all! - * - * @param mapping - * The resolved mapping - * @param strict - * If strict is <code>true</code>, then the property is checked for all resolved corresponding elements. - * E.g. in case of an attribute change, the value of the state before must exist for all corresponding - * elements. If <code>strict = false</code>, then just one elements must at least fulfill the - * precondition. - */ - static void validateElementStates(ResolvedSymbolicReferences mapping, boolean strict) { - final boolean forward = mapping.getDirection() == ResolvedSymbolicReferences.RESOLVE_UNCHANGED; - - // clear previous validation states - mapping.getValidation().clear(); - - // The validation requires the changes to be ordered! - final List<IndepChange> orderedChanges = orderChanges(mapping.getResolutionByChange().keySet(), !forward); - - for (IndepChange change : orderedChanges) { - - // if invalid, add it to the result - final ValidationResult state = validateElementState(change, mapping, strict, forward); - mapping.getValidation().put(change, state); - } - } - - /** - * Check whether the state before or after the change (with respect to the direction for which the symbolic - * references were resolved) can be found in the model. - * - * Note that {@link UnknownChange}s are not allowed at all! - * - * @param change - * The change which is going to be checked. - * @param changeMapping - * The resolved symbolic references for all changes. - * @param strict - * If strict is <code>true</code>, then the property is checked for all resolved corresponding elements. - * E.g. in case of an attribute change, the value of the state before must exist for all corresponding - * elements. If <code>strict = false</code>, then just one elements must at least fulfill the - * precondition. - * @param forward - * Indicates the direction of resolution and thus determines the state which is going to be checked. - * @return Please see {@link ValidationResult} for details. - */ - static ValidationResult validateElementState(IndepChange change, final ResolvedSymbolicReferences mapping, - boolean strict, boolean forward) { - final Map<IElementReference, List<EObject>> changeMapping = mapping.getResolutionByChange().get(change); - - // unknown change? - if (change instanceof UnknownChange) { - return ValidationResult.UNKNOWN_CHANGE; - } - - // we need at least one corresponding element! - if (changeMapping == null || changeMapping.get(change.getCorrespondingElement()).size() == 0) - return ValidationResult.REFERENCE; - - // check sure that all symbolic references are resolved correctly before checking state - for (IElementReference symref : changeMapping.keySet()) { - /* - * The self reference of model descriptors is an exception here. THe change might even be valid if it is not - * resolved! - */ - if (symref.eContainer() instanceof IModelDescriptor) - continue; - - // check all other regularly. - if (!validateResolution(symref, changeMapping.get(symref))) - return ValidationResult.REFERENCE; - } - - if (forward) { // resolve unchanged state - if (change instanceof IndepAddElementChange) { - return validateAddElementState((IndepAddElementChange) change, changeMapping, strict); - } else if (change instanceof IndepRemoveElementChange) { - return validateRemoveElementState((IndepRemoveElementChange) change, changeMapping, strict); - } else if (change instanceof IndepMoveElementChange) { - return validateMoveElementState((IndepMoveElementChange) change, changeMapping, strict, true); - } else if (change instanceof IndepAddAttributeChange) { - return validateAddAttributeState((IndepAddAttributeChange) change, changeMapping, strict); - } else if (change instanceof IndepRemoveAttributeChange) { - return validateRemoveAttributeState((IndepRemoveAttributeChange) change, changeMapping, strict); - } else if (change instanceof IndepUpdateAttributeChange) { - return validateUpdateAttributeState((IndepUpdateAttributeChange) change, changeMapping, strict, true); - } else if (change instanceof IndepAddReferenceChange) { - return validateAddReferenceState((IndepAddReferenceChange) change, mapping, strict); - } else if (change instanceof IndepRemoveReferenceChange) { - return validateRemoveReferenceState((IndepRemoveReferenceChange) change, mapping, strict); - } else if (change instanceof IndepUpdateReferenceChange) { - return validateUpdateReferenceState((IndepUpdateReferenceChange) change, mapping, strict, true); - } else - throw new IllegalArgumentException("Unknown change type: " + change.eClass().getName()); - - } else { // resolve changed (backward) - if (change instanceof IndepAddElementChange) { - return validateRemoveElementState((IndepAddElementChange) change, changeMapping, strict); - } else if (change instanceof IndepRemoveElementChange) { - return validateAddElementState((IndepRemoveElementChange) change, changeMapping, strict); - } else if (change instanceof IndepMoveElementChange) { - return validateMoveElementState((IndepMoveElementChange) change, changeMapping, strict, false); - } else if (change instanceof IndepAddAttributeChange) { - return validateRemoveAttributeState((IndepAddAttributeChange) change, changeMapping, strict); - } else if (change instanceof IndepRemoveAttributeChange) { - return validateAddAttributeState((IndepRemoveAttributeChange) change, changeMapping, strict); - } else if (change instanceof IndepUpdateAttributeChange) { - return validateUpdateAttributeState((IndepUpdateAttributeChange) change, changeMapping, strict, false); - } else if (change instanceof IndepAddReferenceChange) { - return validateRemoveReferenceState((IndepAddReferenceChange) change, mapping, strict); - } else if (change instanceof IndepRemoveReferenceChange) { - return validateAddReferenceState((IndepRemoveReferenceChange) change, mapping, strict); - } else if (change instanceof IndepUpdateReferenceChange) { - return validateUpdateReferenceState((IndepUpdateReferenceChange) change, mapping, strict, false); - } else - throw new IllegalArgumentException("Unknown change type: " + change.eClass().getName()); - } - } - - /** - * Check that the element refers to the object before or after the change for all (<code>strict = true</code>) or - * for at least one (<code>strict = false</code>) corresponding element. - * - * <ol> - * <li>Determine source and target symbolic references depending on direction. - * <li>Get source and target resolutions (might result in {@link ValidationResult#REFERENCE}. - * <li>Check for all corresponding elements:<br> - * Is the source or the target element set? (might result in {@link ValidationResult#STATE_INVALID}. - * <li>Return {@link ValidationResult#STATE_BEFORE} or {@link ValidationResult#STATE_AFTER}, depending on - * <code>strict</code>. - * </ol> - */ - protected static ValidationResult validateUpdateReferenceState(IndepUpdateReferenceChange change, - ResolvedSymbolicReferences mapping, boolean strict, boolean forward) { - - final Map<IElementReference, List<EObject>> changeMapping = mapping.getResolutionByChange().get(change); - - // get symrefs for source and target - final IElementReference beforeSymRef = forward ? change.getOldReference() : change.getNewReference(); - final IElementReference afterSymRef = !forward ? change.getOldReference() : change.getNewReference(); - - // check symrefs - final SymRefCheck beforeCheck = new SymRefCheck(beforeSymRef, changeMapping, change.getReference().getEType(), - 1); - final SymRefCheck afterCheck = new SymRefCheck(afterSymRef, changeMapping, change.getReference().getEType(), 1); - if (beforeCheck.validationResult != null) - return beforeCheck.validationResult; - if (afterCheck.validationResult != null) - return afterCheck.validationResult; - final EObject beforeElement = beforeCheck.internal || beforeCheck.symRef == null ? null : beforeCheck.elements - .get(0); - final EObject afterElement = afterCheck.internal || afterCheck.symRef == null ? null : afterCheck.elements - .get(0); - - // collect status of all corresponding elements - final ResultAccumulator result = new ResultAccumulator(); - for (EObject element : changeMapping.get(change.getCorrespondingElement())) { - final Object currentElement = element.eGet(change.getReference()); - - if (beforeCheck.internal) { - final IndepChange otherChange = (IndepChange) ExtEcoreUtils.getContainerOfType( - ((ModelDescriptorReference) beforeCheck.symRef).getResolvesTo(), - MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE); - - // now we need to check whether the transitive resolution equals current element - if (currentElement == null) { - // if the actual element is empty, it is only a valid state (after), if the (deletion) change of the - // model descriptor is also state after. - if (ValidationResult.STATE_AFTER.equals(mapping.getValidation().get(otherChange))) { - result.after = true; - } else { - result.invalid = true; // there must be an element but it isn't! - } - } else { - // We need to check whether currentElement is described by the model descriptor of this internal - // reference! - if (ValidationResult.STATE_BEFORE.equals(mapping.getValidation().get(otherChange))) { - /* - * Strictly spoken, we must make sure that currentElement is the one that will be deleted by the - * internal model descriptor. But since the deletion does not include a check whether all - * sub-elements are precisely as expected, we cannot ensure that. So lets just assume that the - * current element is the correct one... SHouldn't be a big deal since it's just the - * validation... - */ - result.before = true; - } - } - } else if (currentElement == null && beforeElement == null) { - result.before = true; - } else if (currentElement != null && currentElement.equals(beforeElement)) { - result.before = true; - } - if (afterCheck.internal) { - /* - * If afterCheck.internal, then it's only state_after if the change of the internal reference is also - * state_after! - */ - final IndepChange otherChange = (IndepChange) ExtEcoreUtils.getContainerOfType( - ((ModelDescriptorReference) afterCheck.symRef).getResolvesTo(), - MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE); - final ValidationResult otherState = mapping.getValidation().get(otherChange); - if (ValidationResult.STATE_AFTER.equals(otherState)) { - result.after |= currentElement != null; - } else { - result.invalid = true; - } - } else { - if (currentElement == null && afterElement == null) { - result.after = true; - } else if (currentElement != null && currentElement.equals(afterElement)) { - result.after = true; - } - } - } - return result.accumulate(strict); - } - - /** - * Checks that at least one referred element exist for all (<code>strict = true</code>) or for at least one ( - * <code>strict = false</code>) corresponding element. - * - * <ol> - * <li>Get symbolic reference. - * <li>Get resolution (might result in {@link ValidationResult#REFERENCE}. - * <li>Check type (might result in {@link ValidationResult#STATE_INVALID}. - * <li>Check for all corresponding elements:<br> - * Is the element set? (might result in {@link ValidationResult#STATE_INVALID}. - * <li>Return {@link ValidationResult#STATE_BEFORE} or {@link ValidationResult#STATE_AFTER}, depending on - * <code>strict</code>. - * </ol> - */ - protected static ValidationResult validateRemoveReferenceState(IndepAddRemReferenceChange change, - ResolvedSymbolicReferences mapping, boolean strict) { - - final Map<IElementReference, List<EObject>> changeMapping = mapping.getResolutionByChange().get(change); - - final SymRefCheck symRefCheck = new SymRefCheck(change.getChangedReference(), changeMapping, change - .getReference().getEType(), change.getChangedReference().getUpperBound()); - - // check validation result - if (symRefCheck.validationResult != null) - return symRefCheck.validationResult; - - final ResultAccumulator result = new ResultAccumulator(); - for (EObject element : changeMapping.get(change.getCorrespondingElement())) { - - // which elements are currently referenced - @SuppressWarnings("unchecked") - final EList<EObject> rawList = (EList<EObject>) element.eGet(change.getReference()); - final List<EObject> list = new ArrayList<EObject>(rawList); - - if (symRefCheck.internal) { - final IndepChange otherChange = (IndepChange) ExtEcoreUtils.getContainerOfType( - ((ModelDescriptorReference) symRefCheck.symRef).getResolvesTo(), - MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE); - if (rawList.isEmpty()) { - // if the actual list is empty, it is only a valid state (after), if the change of the model - // descriptor is also state after. - if (ValidationResult.STATE_AFTER.equals(mapping.getValidation().get(otherChange))) { - result.after = true; - } else { - result.invalid = true; // there must be an element but it isn't! - } - } else { - /* - * Like in validateUpdateReferenceState, we must check whether the model descriptor of the internal - * reference describes any of the current list of elements. However, this is not easy, imagine the - * model descriptor is part of a sub-model! They are (on purpose) not resolved. So we simply assume - * that it is correct. Should work because it's just the validation. - */ - if (ValidationResult.STATE_BEFORE.equals(mapping.getValidation().get(otherChange))) { - result.before = true; - } else { - result.invalid = true; - } - } - } else { // no internal reference! - - list.retainAll(symRefCheck.elements); - - // there must be elements to remove - result.before |= !list.isEmpty(); - // there are already elements removed - result.after |= list.size() < symRefCheck.elements.size(); - } - } - return result.accumulate(strict); - } - - /** - * Checks that the referred element(s) do(es) not already exist, if it is a unique reference, for all ( - * <code>strict = true</code>) or for at least one (<code>strict = false</code>) corresponding element. - * - * Almost the same as {@link MPatchValidator#validateRemoveElementState(IndepAddRemElementChange, Map, boolean)}, - * but the check is reversed. - */ - protected static ValidationResult validateAddReferenceState(IndepAddRemReferenceChange change, - ResolvedSymbolicReferences mapping, boolean strict) { - - final Map<IElementReference, List<EObject>> changeMapping = mapping.getResolutionByChange().get(change); - - final SymRefCheck symRefCheck = new SymRefCheck(change.getChangedReference(), changeMapping, change - .getReference().getEType(), change.getChangedReference().getUpperBound()); - - // check validation result - if (symRefCheck.validationResult != null) - return symRefCheck.validationResult; - - final ResultAccumulator result = new ResultAccumulator(); - if (symRefCheck.internal) { - /* - * If it's an internal reference, it can always be added. However, if the internal model descriptor exactly - * resolves to one of the elements, we found the state_after ;-) - */ - final IndepChange otherChange = (IndepChange) ExtEcoreUtils.getContainerOfType( - ((ModelDescriptorReference) symRefCheck.symRef).getResolvesTo(), - MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE); - final ValidationResult otherState = mapping.getValidation().get(otherChange); - if (ValidationResult.STATE_BEFORE.equals(otherState)) { - result.before = true; - } else if (ValidationResult.STATE_INVALID.equals(otherState)) { - result.invalid = true; - } else if (ValidationResult.STATE_AFTER.equals(otherState)) { - // since the addition is checked thoroughly (unlike RemoveReferenceState), the actual element must be - // resolved! - final Map<IElementReference, List<EObject>> otherMapping = mapping.getResolutionByChange().get( - otherChange); - final IElementReference selfReference = ((IndepAddRemElementChange) otherChange).getSubModelReference(); - final List<EObject> addedElements = otherMapping.get(selfReference); // already added (roots of) - // sub-models - final List<? extends EObject> allAddedElements = ExtEcoreUtils.flattenEObjects(addedElements); - symRefCheck.elements.addAll(allAddedElements); - } - } - for (EObject element : changeMapping.get(change.getCorrespondingElement())) { - // which elements are currently referenced - @SuppressWarnings("unchecked") - final EList<EObject> rawList = (EList<EObject>) element.eGet(change.getReference()); - final List<EObject> list = new ArrayList<EObject>(rawList); - list.retainAll(symRefCheck.elements); - - if (!symRefCheck.internal) { - // there must be elements that are not yet added (does not apply for internal reference) - result.before |= list.size() < symRefCheck.elements.size(); - } - // there are already elements added - result.after |= !list.isEmpty(); - } - return result.accumulate(strict); - } - - /** - * Check that the attribute has the value before the change for all (<code>strict = true</code>) or for at least one - * (<code>strict = false</code>) corresponding element. - */ - protected static ValidationResult validateUpdateAttributeState(IndepUpdateAttributeChange change, - Map<IElementReference, List<EObject>> map, boolean strict, boolean forward) { - - // get value depending on the direction - final Object oldValue = forward ? change.getOldValue() : change.getNewValue(); - final Object newValue = !forward ? change.getOldValue() : change.getNewValue(); - - // collect status of all corresponding elements - final ResultAccumulator result = new ResultAccumulator(); - for (EObject element : map.get(change.getCorrespondingElement())) { - final Object currentValue = element.eGet(change.getChangedAttribute()); - if (currentValue == null && oldValue == null) { - result.before = true; - } else if (currentValue != null && currentValue.equals(oldValue)) { - result.before = true; - } else if (currentValue == null && newValue == null) { - result.after = true; - } else if (currentValue != null && currentValue.equals(newValue)) { - result.after = true; - } else { - result.invalid = true; - } - } - return result.accumulate(strict); - } - - /** - * Check if the attribute value does exist for all (<code>strict = true</code>) or for at least one ( - * <code>strict = false</code>) corresponding element. - * - * This either returns {@link ValidationResult#STATE_BEFORE} or {@link ValidationResult#STATE_AFTER}, depending on - * whether the value of interest does or does not exist in the current list. - */ - protected static ValidationResult validateRemoveAttributeState(IndepAddRemAttributeChange change, - Map<IElementReference, List<EObject>> map, boolean strict) { - // get value to remove - final Object value = change.getValue(); - - final ResultAccumulator result = new ResultAccumulator(); - for (EObject element : map.get(change.getCorrespondingElement())) { - // get current value - @SuppressWarnings("unchecked") - final EList<Object> currentValues = (EList<Object>) element.eGet(change.getChangedAttribute()); - - // the value must not yet exist - result.before |= currentValues.contains(value); - // the value does exist - result.after |= !currentValues.contains(value); - } - return result.accumulate(strict); - } - - /** - * Check if the attribute value does not already exists for all (<code>strict = true</code>) or for at least one ( - * <code>strict = false</code>) corresponding element. - * - * Almost the same as {@link MPatchValidator#validateRemoveAttributeState(IndepAddRemAttributeChange, Map, boolean)} - * , but the check is reversed. - */ - protected static ValidationResult validateAddAttributeState(IndepAddRemAttributeChange change, - Map<IElementReference, List<EObject>> map, boolean strict) { - // get value to add - final Object value = change.getValue(); - - final ResultAccumulator result = new ResultAccumulator(); - for (EObject element : map.get(change.getCorrespondingElement())) { - // get current value - @SuppressWarnings("unchecked") - final EList<Object> currentValues = (EList<Object>) element.eGet(change.getChangedAttribute()); - - // the value does exist - result.before |= !currentValues.contains(value); - // the value must not exist - result.after |= currentValues.contains(value); - } - return result.accumulate(strict); - } - - /** - * Check if the element to move exists in the source element and that it is possible to add it to the target element - * for all (<code>strict = true</code>) or for at least one (<code>strict = false</code>) corresponding element. - * - * <ol> - * <li>Determine old and new parents depending on direction. - * <li>Check for all corresponding elements:<br> - * Is the old or the new parent or neither of them set? (might result in {@link ValidationResult#STATE_INVALID}. - * <li>Return {@link ValidationResult#STATE_BEFORE} or {@link ValidationResult#STATE_AFTER}, depending on - * <code>strict</code>. - * </ol> - */ - protected static ValidationResult validateMoveElementState(IndepMoveElementChange change, - Map<IElementReference, List<EObject>> map, boolean strict, boolean forward) { - - // get the specification of the movement - final EReference oldContainment = forward ? change.getOldContainment() : change.getNewContainment(); - final EReference newContainment = forward ? change.getNewContainment() : change.getOldContainment(); - final IElementReference oldParentRef = forward ? change.getOldParent() : change.getNewParent(); - final IElementReference newParentRef = !forward ? change.getOldParent() : change.getNewParent(); - if (oldParentRef == null || newParentRef == null || oldContainment == null || newContainment == null) - throw new IllegalStateException( - "old and new parent and their containment features must be defined in the change but they are not!"); - - // if we have many corresponding elements, check that the container can hold many of them! - final Collection<EObject> correspondingElements = map.get(change.getCorrespondingElement()); - if (!newContainment.isMany() && correspondingElements.size() > 1) - return ValidationResult.REFERENCE; - - // get the old and the new parents and check the resolution - // Note: the new parent might not yet exist (being internal)! - final SymRefCheck oldParentCheck = new SymRefCheck(oldParentRef, map, oldContainment.getEContainingClass(), 1); - final SymRefCheck newParentCheck = new SymRefCheck(newParentRef, map, newContainment.getEContainingClass(), 1); - if (oldParentCheck.validationResult != null) - return oldParentCheck.validationResult; - if (newParentCheck.validationResult != null) - return newParentCheck.validationResult; - final EObject oldParent = oldParentCheck.internal ? null : oldParentCheck.elements.get(0); - final EObject newParent = newParentCheck.internal ? null : newParentCheck.elements.get(0); - - final ResultAccumulator result = new ResultAccumulator(); - if (oldParentCheck.internal) { - // The internal references ensures via change dependency that the before-state is valid! This can occur when - // we move from a removed sub-model. - result.before = true; - } else { - for (EObject element : map.get(change.getCorrespondingElement())) { - // get current parent - final Object currentParent = element.eContainer(); - final EReference currentContainment = element.eContainmentFeature(); - - // check state; NB: null values are NOT allowed here! - if (currentParent == null || currentContainment == null) { - result.invalid = true; // should never occur! - } else if (currentParent.equals(oldParent) && currentContainment.equals(oldContainment)) { - result.before = true; - } else if (currentParent.equals(newParent) && currentContainment.equals(newContainment)) { - result.after = true; - } else { // if newParentCheck.internal, then it's invalid! because we need state_before! - result.invalid = true; - } - } - } - return result.accumulate(strict); - } - - /** - * Check if the element to remove exists in at least one (<code>strict = false</code>) or in all ( - * <code>strict = true</code>) corresponding elements. - * - * Get all elements to delete and check whether they are distributed over all parents. - * - * Unlike {@link MPatchValidator#validateAddElementState(IndepAddRemElementChange, Map, boolean)}, this does not - * check whether they elements to delete are really described by the model descriptors. This allows the user to - * delete more elements than only strictly those that are deleted. - */ - protected static ValidationResult validateRemoveElementState(IndepAddRemElementChange change, - Map<IElementReference, List<EObject>> map, boolean strict) { - - // get elements to delete - final SymRefCheck toDeleteCheck = new SymRefCheck(change.getSubModelReference(), map, change.getSubModel() - .getType(), change.getSubModelReference().getUpperBound()); - if (toDeleteCheck.symRef == null || toDeleteCheck.internal) - throw new IllegalStateException("Submodel reference must neither be null nor an internal reference!"); - final int elementCountToDelete = toDeleteCheck.elements.size(); - - final ResultAccumulator result = new ResultAccumulator(); - if (elementCountToDelete > 0) { - for (final EObject parent : map.get(change.getCorrespondingElement())) { - if (change.getContainment().isMany()) { - - // get the actual children and calculate intersection - @SuppressWarnings("unchecked") - final EList<EObject> rawList = (EList<EObject>) parent.eGet(change.getContainment()); - final List<EObject> toDelete = new ArrayList<EObject>(rawList); - toDelete.retainAll(toDeleteCheck.elements); - toDeleteCheck.elements.removeAll(toDelete); - - // there must be elements to remove - result.before |= !toDelete.isEmpty(); - result.after |= toDelete.isEmpty(); - - } else { - final Object toDelete = parent.eGet(change.getContainment()); - - // is it an element to delete? if so, remove it from toDeleteCheck and update result.before - result.invalid |= toDelete == null || !toDeleteCheck.elements.contains(toDelete); - result.before |= toDelete != null && toDeleteCheck.elements.remove(toDelete); - } - } - } else { - // no elements to delete... - result.after = true; - } - - // there are already elements removed - /* - * In case the change cannot be applied to all resolved corresponding elements, setting result.after here - * yields a wrong result. This setting hasn't been proven to be useful at all, so we deactivate it for the - * time being. - */ -// result.after |= elementCountToDelete > toDeleteCheck.elements.size(); - return result.accumulate(strict); - } - - /** - * If <code>strict</code> equals <code>true</code>, then all corresponding elements must be able to add an element; - * if <code>false</code>, then at least one corresponding element must be able to add an element. With - * {@link IModelDescriptor#isDescriptorOf(EObject)} it is also checked whether the element already exists. - */ - protected static ValidationResult validateAddElementState(IndepAddRemElementChange change, - Map<IElementReference, List<EObject>> map, boolean strict) { - - // get elements that might be instances of the added element already - final SymRefCheck toAddCheck = new SymRefCheck(change.getSubModelReference(), map, change.getSubModel() - .getType(), change.getSubModelReference().getUpperBound()); - if (toAddCheck.symRef == null || toAddCheck.internal) - throw new IllegalStateException("Submodel reference must neither be null nor an internal reference!"); - - // are they really added elements or does the symbolic reference just match - for (int i = toAddCheck.elements.size() - 1; i >= 0; i--) { - final EObject element = toAddCheck.elements.get(i); - if (change.getSubModel().isDescriptorFor(element, true) == null) - toAddCheck.elements.remove(i); - } - - final ResultAccumulator result = new ResultAccumulator(); - for (final EObject parent : map.get(change.getCorrespondingElement())) { - if (change.getContainment().isMany()) { - - // get the actual children and calculate intersection - @SuppressWarnings("unchecked") - final EList<EObject> rawList = (EList<EObject>) parent.eGet(change.getContainment()); - final List<EObject> added = new ArrayList<EObject>(rawList); - added.retainAll(toAddCheck.elements); - toAddCheck.elements.removeAll(added); - - // there must be elements to add - result.before |= added.isEmpty(); - result.after |= !added.isEmpty(); - - } else { - final Object toAdd = parent.eGet(change.getContainment()); - - // is it possible to add the element? if so, remove it from toAddCheck and update result.before - result.invalid |= toAdd != null && !toAddCheck.elements.contains(toAdd); - result.before |= toAdd == null; - result.after |= toAddCheck.elements.remove(toAdd); - } - } - // there are already elements removed - return result.accumulate(strict); - } - - /** - * Get all {@link EReference}s which need to be resolved for the particular change. - * - * @param eClass - * The eclass of the change, e.g. {@link IndepAddElementChange}, {@link IndepUpdateReferenceChange}, etc. - * @param direction - * Return only relevant references; e.g. if <code>direction</code> = - * {@link ResolvedSymbolicReferences#RESOLVE_UNCHANGED}, then for {@link IndepUpdateReferenceChange} only - * {@link IndepUpdateReferenceChange#setOldReference(IElementReference)} will be returned, not - * {@link IndepUpdateReferenceChange#setNewReference(IElementReference)}. - * @return A collection of references which are relevant for the given {@link EClass}. - */ - static Collection<EReference> getImportantReferencesFor(EClass eClass, int direction) { - final Collection<EReference> refs = new ArrayList<EReference>(); - if (equalEClasses(eClass, MPatchPackage.Literals.CHANGE_GROUP)) { - // we are not interested in groups here! - } else if (equalEClasses(eClass, MPatchPackage.Literals.UNKNOWN_CHANGE)) { - // also skip unknown changes! - } else { - - refs.add(MPatchPackage.Literals.INDEP_CHANGE__CORRESPONDING_ELEMENT); - if (equalEClasses(eClass, MPatchPackage.Literals.INDEP_ADD_ELEMENT_CHANGE)) { - // if (direction == ResolvedSymbolicReferences.RESOLVE_CHANGED) { - refs.add(MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE__SUB_MODEL_REFERENCE); - // } - } else if (equalEClasses(eClass, MPatchPackage.Literals.INDEP_REMOVE_ELEMENT_CHANGE)) { - // if (direction == ResolvedSymbolicReferences.RESOLVE_UNCHANGED) { - refs.add(MPatchPackage.Literals.INDEP_ADD_REM_ELEMENT_CHANGE__SUB_MODEL_REFERENCE); - // } - } else if (equalEClasses(eClass, MPatchPackage.Literals.INDEP_MOVE_ELEMENT_CHANGE)) { - // if (direction == ResolvedSymbolicReferences.RESOLVE_UNCHANGED) { - refs.add(MPatchPackage.Literals.INDEP_MOVE_ELEMENT_CHANGE__OLD_PARENT); - // } else if (direction == ResolvedSymbolicReferences.RESOLVE_CHANGED) { - refs.add(MPatchPackage.Literals.INDEP_MOVE_ELEMENT_CHANGE__NEW_PARENT); - // } - } else if (equalEClasses(eClass, MPatchPackage.Literals.INDEP_ADD_REFERENCE_CHANGE)) { - // if (direction == ResolvedSymbolicReferences.RESOLVE_CHANGED) { - refs.add(MPatchPackage.Literals.INDEP_ADD_REM_REFERENCE_CHANGE__CHANGED_REFERENCE); - // } - } else if (equalEClasses(eClass, MPatchPackage.Literals.INDEP_REMOVE_REFERENCE_CHANGE)) { - // if (direction == ResolvedSymbolicReferences.RESOLVE_UNCHANGED) { - refs.add(MPatchPackage.Literals.INDEP_ADD_REM_REFERENCE_CHANGE__CHANGED_REFERENCE); - // } - } else if (equalEClasses(eClass, MPatchPackage.Literals.INDEP_UPDATE_REFERENCE_CHANGE)) { - // if (direction == ResolvedSymbolicReferences.RESOLVE_UNCHANGED) { - refs.add(MPatchPackage.Literals.INDEP_UPDATE_REFERENCE_CHANGE__OLD_REFERENCE); - // } else if (direction == ResolvedSymbolicReferences.RESOLVE_CHANGED) { - refs.add(MPatchPackage.Literals.INDEP_UPDATE_REFERENCE_CHANGE__NEW_REFERENCE); - // } - } - } - return refs; - } - - /** - * Check whether two eclasses are equal. - * - * @param eClass1 - * An eclass. - * @param eClass2 - * Another eclass. - * @return <code>true</code>, if their classifier IDs equal; <code>false</code> otherwise. - */ - protected static boolean equalEClasses(EClass eClass1, EClass eClass2) { - // return eClass1.getInstanceClassName().equals(eClass2.getInstanceClassName()); - return eClass1.getClassifierID() == eClass2.getClassifierID(); - } - - /** - * Order the given changes according to their dependencies. So in order to result in a useful order, make sure that - * the dependencies are set correctly. - * - * The following order will be created: <br> - * <all changes which are dependants of deletions> <br> - * <all deletions> <br> - * <all additions> <br> - * <all changes which depend on additions> - * - * @param changes - * Changes. - * @param forward - * The direction of application. - * @return A flat and ordered list of the input. - */ - public static List<IndepChange> orderChanges(final Set<IndepChange> changes, boolean forward) { - - // 0. a list containing the resulting order - final List<IndepChange> list = new ArrayList<IndepChange>(changes.size()); - - // 1. iterate over all changes and put all additions and deletions to the list - for (IndepChange change : changes) { - if ((change instanceof IndepAddElementChange && forward) - || ((change instanceof IndepRemoveElementChange && !forward))) { - list.add(change); // add additions - } else if ((change instanceof IndepRemoveElementChange && forward) - || ((change instanceof IndepAddElementChange && !forward))) { - list.add(0, change); // insert deletions at the start - } - } - - // 2. evaluate all dependencies: - // (iterate over a copy to be able to change the original list) - // -> this might introduce duplicates which need to be removed later! - for (IndepChange change : new ArrayList<IndepChange>(list)) { - if ((change instanceof IndepAddElementChange && forward) - || ((change instanceof IndepRemoveElementChange && !forward))) { - list.addAll(change.getDependants()); - } else if ((change instanceof IndepRemoveElementChange && forward) - || ((change instanceof IndepAddElementChange && !forward))) { - list.addAll(0, change.getDependsOn()); - } - } - - // 3. add all changes which were not considered so far - final HashSet<IndepChange> tmpDiffs = new HashSet<IndepChange>(changes); - tmpDiffs.removeAll(list); - list.addAll(tmpDiffs); - list.retainAll(changes); - - // 4. remove duplicates introduced in 2. - if (list.size() > changes.size()) { - final Set<IndepChange> elements = new HashSet<IndepChange>(changes.size()); - for (int i = list.size() - 1; i >= 0; i--) { - if (elements.contains(list.get(i))) - list.remove(i); - else - elements.add(list.get(i)); - } - } - - // 5. double check that we do exactly have the number of changes we require! - if (list.size() != changes.size() || !changes.containsAll(list)) { - throw new IllegalStateException( - "The number of ordered changes does not equal the number of total changes! " - + "Please check ordering algorithm!"); - } - - return list; - } - -} diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/ResultAccumulator.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/ResultAccumulator.java deleted file mode 100644 index 78c3ca54a..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/ResultAccumulator.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.util; - -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences.ValidationResult; - -/** - * Helper class for accumulating the validation result. - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ -class ResultAccumulator { - - /** - * Clients should set it to <code>true</code>, if there is a case in which the state before the change is found in - * the resolved model elements. - */ - boolean before = false; - /** - * Clients should set it to <code>true</code>, if there is a case in which the state after the change is found in the - * resolved model elements. - */ - boolean after = false; - /** - * Clients should set it to <code>true</code>, if there is a case in which neither state could be found in the - * resolved model elements. - */ - boolean invalid = false; - - /** - * We got the problem that we need to accumulate all status to one single status! - * - * @param strict - * If strict is <code>true</code>, then the property is checked for all resolved corresponding elements. - * E.g. in case of an attribute change, the value of the state before must exist for all corresponding - * elements. If <code>strict = false</code>, then just one elements must at least fulfill the - * precondition. - * @param before - * Indicates whether elements are found that have the status before the change. - * @param after - * Indicates whether elements are found that have the status after the change. - * @param invalid - * Indicates whether elements are found that do not have a valid status. - * @return An accumulated result. - */ - ValidationResult accumulate(boolean strict) { - if (strict) { - if (invalid) // strict doesn't allow any invalid state - return ValidationResult.STATE_INVALID; - if (before && !after) // perfect, all are before! - return ValidationResult.STATE_BEFORE; - if (!before && after) // perfect, all are after! - return ValidationResult.STATE_AFTER; - return ValidationResult.STATE_INVALID; // mixtures arn't that good... - } else { - if (before) - return ValidationResult.STATE_BEFORE; - if (after) // && !before - return ValidationResult.STATE_AFTER; - if (invalid) // && !before && !after - return ValidationResult.STATE_INVALID; - return ValidationResult.STATE_INVALID; // no state isn't good either! - } - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/SymRefCheck.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/SymRefCheck.java deleted file mode 100644 index d701c22db..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/util/SymRefCheck.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.compare.mpatch.IElementReference; -import org.eclipse.emf.compare.mpatch.ModelDescriptorReference; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences.ValidationResult; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EObject; - -/** - * Wrapper class for Symbolic reference checks. - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ -class SymRefCheck { - - /** - * The symbolic references that was checked. Please see constructor documentation for details. - */ - final IElementReference symRef; - - /** - * The validation result. Please see constructor documentation for details. - */ - final ValidationResult validationResult; - - /** - * The list of resolved model elements. Please see constructor documentation for details. - */ - final List<EObject> elements; - - /** - * Whether this is an internal reference. Please see constructor documentation for details. - */ - final boolean internal; - - /** - * Check whether the given symbolic references is resolved successfully. - * - * The result should check in this order: - * <ol> - * <li><code>symRef</code> might be <code>null</code>! - * <li>if <code>internal</code> is true, ignore <code>elements</code> and the <code>validationResult</code> - * <li>then, if the bounds are ok and some elements of the correct type are resolved, <code>validationResult</code> - * is <code>null</code>. otherwise, <code>validationResult</code> either results in - * {@link ValidationResult#REFERENCE} or {@link ValidationResult#STATE_INVALID}. - * </ol> - * - * - * @param symRef - * A given symbolic reference. - * @param map - * The resolution of it. - * @param type - * The type which all resolved elements must have. - * @param upperBound - * The maximum number of resolved elements. - */ - public SymRefCheck(IElementReference symRef, Map<IElementReference, List<EObject>> map, EClassifier type, - int upperBound) { - // default values: - ValidationResult validation = null; - elements = new ArrayList<EObject>(); - boolean internal = false; - - // perform checks: - if (symRef == null) { - // default values - } else if (symRef instanceof ModelDescriptorReference) { - internal = true; - } else { - // symref is set, so we need to check the resolution! - final List<EObject> list = map.get(symRef); - if (list != null) - elements.addAll(list); - if (elements.size() == 0 || (elements.size() > upperBound && upperBound > 0)) { - validation = ValidationResult.REFERENCE; - } else { - - // check type - for (EObject element : elements) { - if (!type.isInstance(element)) { - validation = ValidationResult.STATE_INVALID; - break; - } - } - } - } - this.symRef = symRef; - this.validationResult = validation; - this.internal = internal; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizard.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizard.java deleted file mode 100644 index 987144f4a..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizard.java +++ /dev/null @@ -1,454 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.wizards; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.compare.CompareUI; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; -import org.eclipse.emf.compare.mpatch.MPatchModel; -import org.eclipse.emf.compare.mpatch.apply.ApplyActivator; -import org.eclipse.emf.compare.mpatch.common.util.CommonUtils; -import org.eclipse.emf.compare.mpatch.common.util.ExtensionManager; -import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants; -import org.eclipse.emf.compare.mpatch.extension.IMPatchApplication; -import org.eclipse.emf.compare.mpatch.extension.MPatchApplicationResult; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences; -import org.eclipse.emf.compare.mpatch.provider.MPatchItemProviderAdapterFactory; -import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.impl.ResourceImpl; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; -import org.eclipse.emf.edit.provider.ComposedAdapterFactory; -import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; -import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.ide.IDE; - -/** - * A wizard which takes an MPatch (instance of {@link MPatchModel}) and an emf model as input, resolves all - * symbolic references of the diff, and creates a new emfdiff (instance of {@link ComparisonSnapshot}) and a - * new model such that the emfdiff can be used to transfer the mpatch to the target model.<br> - * <br> - * <i>Example:</i> - * <ol> - * <li>A file <code>diff.mpatch</code> contains an mpatch for models of type 'mymodel'. - * <li>An example model <code>test.mymodel</code> contains an instance of that type of models. - * <li>The wizard takes both files as input and tries to resolve all symbolic references from the - * <code>diff.mpatch</code> in <code>test.mymodel</code>. - * <li>Then it asks the user to store the results in an EMF Compare based diff, e.g. <code>diff.emfdiff</code>. - * <li>Afterwards it asks the user to store the resulting model in a new file, e.g. <code>test2.mymodel</code>. - * <li>In the end, it opens the EMF Compare GUI to revise the application of the diff. - * </ol> - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ -public class ApplyWizard extends Wizard implements INewWizard { - - private static final String WIZARD_ICON = "icons/mpatch.gif"; - - /** - * Defines whether the intermediate emfdiff and the temporary new model should be saved. If set to - * <code>false</code>, then these artifacts are only handled in-memory. - */ - boolean saveIntermediateFiles; - - /** - * Defines whether the binding between the differences and the model, to which the differences were - * applied, should be saved into a file. - */ - boolean saveBinding; - - /** Defines whether already applied changes shall be detected and bound. */ - boolean respectApplied; - - /** Singleton diff applier. */ - protected IMPatchApplication mPatchApplication; - - /** We need that for opening the EMF Compare GUI in the end. */ - protected IWorkbench workbench; - - /** The initial selected MPatch when the wizard was launched (might be <code>null</code>). */ - protected IFile mPatchFile; - - /** The initial selected model when the wizard was launched (might be <code>null</code>). */ - protected URI modelURI; - - /** The result of the page asking the user for the diff. */ - protected MPatchModel mpatch; - - /** The result of the page asking the user for the model to which the diff should be applied. */ - protected Resource modelResource; - - /** The model element in modelResource to which the diff should be applied. */ - private EObject modelTarget; - - /** The result of the page performing the symbolic reference resolution. */ - protected ResolvedSymbolicReferences resolvedElements; - - /** The result of the page asking the user for the file to which the emfdiff should be saved. */ - protected IFile emfdiffFile; - - /** The result of the page asking the user for the file to which the new model should be saved. */ - protected IFile newModelFile; - - /** - * The result of the page asking the user for the file for the binding between the differences and the - * model. - */ - private IFile bindingFile; - - private ApplyWizardResolvePage symbolicReferenceResolutionPage; - - private ApplyWizardNewModelPage storeModelPage; - - private ApplyWizardSummaryPage summaryPage; - - private ApplyWizardSelectMPatchPage selectMPatchPage; - - private ApplyWizardSelectModelPage selectModelPage; - - private ApplyWizardNewEmfdiffPage storeDiffPage; - - private ApplyWizardSaveBindingPage storeBindingPage; - - private ComposedAdapterFactory adapterFactory; - - /** @see {@link ApplyWizard} */ - public ApplyWizard() { - // load a diff applier extension - mPatchApplication = ExtensionManager.getSelectedApplication(); - } - - @Override - public void addPages() { - // get mpatch file from default selection - IStructuredSelection selection = null; - if (mPatchFile != null) { - selection = new StructuredSelection(mPatchFile); - } - - adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); - adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory()); - adapterFactory.addAdapterFactory(new MPatchItemProviderAdapterFactory()); - adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory()); - adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); - - // now lets create the pages - selectMPatchPage = new ApplyWizardSelectMPatchPage("Select " + MPatchConstants.MPATCH_LONG_NAME, - mPatchFile, adapterFactory); - selectModelPage = new ApplyWizardSelectModelPage("Select Model", modelURI, adapterFactory); - symbolicReferenceResolutionPage = new ApplyWizardResolvePage("Resolve " - + MPatchConstants.SYMBOLIC_REFERENCES_NAME, adapterFactory); - storeModelPage = new ApplyWizardNewModelPage("Store New Model", selection); - storeDiffPage = new ApplyWizardNewEmfdiffPage("Store Emfdiff", selection); - storeBindingPage = new ApplyWizardSaveBindingPage("Store Binding", selection); - summaryPage = new ApplyWizardSummaryPage("Summary"); - addPage(selectMPatchPage); - addPage(selectModelPage); - addPage(symbolicReferenceResolutionPage); - addPage(storeModelPage); - addPage(storeDiffPage); - addPage(storeBindingPage); - addPage(summaryPage); - } - - @Override - public IWizardPage getNextPage(IWizardPage page) { - if (page.equals(symbolicReferenceResolutionPage)) { - saveIntermediateFiles = symbolicReferenceResolutionPage.storeIntermediateModels(); - saveBinding = symbolicReferenceResolutionPage.storeBinding(); - if (saveIntermediateFiles) { - return storeModelPage; - } else if (saveBinding) { - return storeBindingPage; - } else { - return summaryPage; - } - } else if (page.equals(storeDiffPage)) { - if (saveBinding) { - return storeBindingPage; - } else { - return summaryPage; - } - } else { - return super.getNextPage(page); - } - } - - @Override - public boolean canFinish() { - for (IWizardPage page : getPages()) { - if (!saveIntermediateFiles && (page.equals(storeModelPage) || page.equals(storeDiffPage))) { - continue; - } - if (!saveBinding && page.equals(storeBindingPage)) { - continue; - } - if (!page.isPageComplete()) { - return false; - } - } - return true; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - // check the initial selection for a valid input file - for (Object obj : selection.toArray()) { - if (obj instanceof IFile) { - final IFile file = (IFile)obj; - if (MPatchConstants.FILE_EXTENSION_MPATCH.equals(file.getFileExtension()) - && mPatchFile == null) { - mPatchFile = file; - } else if (modelURI == null) { - modelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true); - } - } - } - this.workbench = workbench; - - // set some wizard attributes - setWindowTitle("Apply " + MPatchConstants.MPATCH_LONG_NAME); - final URL imageURL = ApplyActivator.getDefault().getBundle().getEntry(ApplyWizard.WIZARD_ICON); - setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(imageURL)); - - // if a model is open, get its uri - if (modelURI == null) { - modelURI = CommonUtils.getCurrentEditorFileInputUri(); - } - - // maybe the MPatch is open?! then erase the default model uri again... - if (modelURI != null && mPatchFile != null) { - final URI uri = URI.createPlatformResourceURI(mPatchFile.getFullPath().toString(), true); - if (modelURI.equals(uri)) { - modelURI = null; - } - } - } - - /** - * At last, new {@link Resource}s for the new model and the emfdiff are created and the respective objects - * are saved. If that was successful, the EMF Compare editor is opened.<br> - * <br> - * In case the files cannot be saved, an error message will be shown to the user. - */ - @Override - public boolean performFinish() { - final boolean reviewDiffApplication = summaryPage.reviewDiffApplication(); - final EObject model = modelResource.getContents().get(0); - final boolean[] result = new boolean[] {true}; // easy way to store return value - - try { - /* - * Use a blocking progress monitor! - */ - getContainer().run(false, false, new IRunnableWithProgress() { - - public void run(IProgressMonitor monitor) throws InvocationTargetException, - InterruptedException { - - monitor.beginTask("Applying MPatch...", 10); - monitor.worked(2); // PROGRESS MONITOR - - final Map<Integer, Boolean> options = new HashMap<Integer, Boolean>(); - options.put(IMPatchApplication.OPTION_STORE_BINDING, saveBinding); - options.put(IMPatchApplication.OPTION_MATCH_APPLIED_CHANGES, respectApplied); - - try { - if (!saveIntermediateFiles && !reviewDiffApplication) { - MPatchApplicationResult result = mPatchApplication.applyMPatch(resolvedElements, - options); - result.showDialog(getShell(), adapterFactory); - modelResource.save(null); - } else { - - final EObject copyModel = EcoreUtil.copy(model); // create a copy of the model - - // initialize resources (which are required for EMF Compare to work - final Resource copyModelResource; - final Resource emfdiffResource; - if (saveIntermediateFiles) { - copyModelResource = new XMIResourceImpl(URI.createPlatformResourceURI( - newModelFile.getFullPath().toString(), true)); - emfdiffResource = new XMIResourceImpl(URI.createPlatformResourceURI( - emfdiffFile.getFullPath().toString(), true)); - } else { - copyModelResource = new ResourceImpl(modelResource.getURI()); - emfdiffResource = new ResourceImpl(); - } - copyModelResource.getContents().add(copyModel); // new model must be contained in - // a resource - // beforehand - monitor.worked(2); // PROGRESS MONITOR - - // apply differences! - MPatchApplicationResult result = mPatchApplication.applyMPatch(resolvedElements, - options); - monitor.worked(2); // PROGRESS MONITOR - result.showDialog(getShell(), adapterFactory); - modelResource.save(null); - final boolean useIds = false; // in case of id-based models, new ids were added! - final ComparisonSnapshot emfdiff = CommonUtils.createEmfdiff(model, copyModel, - useIds); - - // save resources, if necessary - if (saveIntermediateFiles) { - copyModelResource.save(null); - emfdiffResource.getContents().add(emfdiff); - emfdiffResource.save(null); - if (reviewDiffApplication) { - IDE.openEditor(workbench.getActiveWorkbenchWindow().getActivePage(), - emfdiffFile); - } - } else if (reviewDiffApplication) { - CompareUI.openCompareEditor(new ModelCompareEditorInput(emfdiff)); - } - monitor.worked(2); // PROGRESS MONITOR - } - - // if storeBinding is true, save the binding! - if (saveBinding) { - try { - Resource bindingResource = new XMIResourceImpl(URI.createPlatformResourceURI( - bindingFile.getFullPath().toString(), true)); - bindingResource.getContents().add(resolvedElements.getMPatchModelBinding()); - bindingResource.save(null); - } catch (IOException e) { - ApplyActivator.getDefault().logError("An error occurred saving the binding.", - e); - MessageDialog.openError(getShell(), "Could not save binding", - "An error occurred saving the binding.\nPlease check error log for details.\n\n" - + e.getMessage()); - } - } - monitor.done(); // PROGRESS MONITOR - - } catch (final Exception e) { - ApplyActivator.getDefault().logError( - "An error occured while saving the selected files", e); - MessageDialog.openError(getShell(), "An error occured", - "An error occured while applying differences:\n" + e.getMessage()); - result[0] = false; - } - } - }); - - } catch (InvocationTargetException e) { - // Ignore - } catch (InterruptedException e) { - // Ignore - } - - return result[0]; - } - - // //////////////////// Some getters and setters for commonly used data in the wizard - - /** The result of the page asking the user for the mpatch. */ - MPatchModel getMPatch() { - return mpatch; - } - - /** The result of the page asking the user for the mpatch. */ - void setMPatch(MPatchModel mpatch) { - this.mpatch = mpatch; - } - - /** The result of the page asking the user for the model to which the diff should be applied. */ - Resource getModelResource() { - return modelResource; - } - - /** The result of the page asking the user for the model to which the diff should be applied. */ - void setModelResource(Resource modelResource) { - this.modelResource = modelResource; - } - - // /** A copy of the input model in <code>modelResource</code> which in the end contains all applied - // differences. */ - // void setNewModel(EObject newModel) { - // this.newModel = newModel; - // } - - /** The result of the page performing the symbolic reference resolution. */ - ResolvedSymbolicReferences getResolvedElements() { - return resolvedElements; - } - - /** The result of the page performing the symbolic reference resolution. */ - void setResolvedElements(ResolvedSymbolicReferences resolvedElements) { - this.resolvedElements = resolvedElements; - } - - /** The result of the page asking the user for the file to which the emfdiff should be saved. */ - void setEmfdiff(IFile emfdiffFile) { - this.emfdiffFile = emfdiffFile; - } - - /** The result of the page asking the user for the file to which the emfdiff should be saved. */ - IFile getEmfdiffFile() { - return emfdiffFile; - } - - /** The result of the page asking the user for the file to which the new model should be saved. */ - void setNewModelFile(IFile newModelFile) { - this.newModelFile = newModelFile; - } - - /** The result of the page asking the user for the file to which the new model should be saved. */ - IFile getNewModelFile() { - return newModelFile; - } - - /** The result of the page asking the user for the file to which the binding should be saved. */ - void setBindingFile(IFile file) { - this.bindingFile = file; - } - - /** The result of the page asking the user for the file to which the binding should be saved. */ - IFile getBindingFile() { - return bindingFile; - } - - /** - * The specific model element in <code>modelResource</code> from the page asking the user for the target - * model. - */ - void setModelTarget(EObject modelTarget) { - this.modelTarget = modelTarget; - } - - /** - * The specific model element in <code>modelResource</code> from the page asking the user for the target - * model. - */ - EObject getModelTarget() { - return modelTarget; - } -} diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardNewEmfdiffPage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardNewEmfdiffPage.java deleted file mode 100644 index 35e821f82..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardNewEmfdiffPage.java +++ /dev/null @@ -1,68 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply.wizards;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
-
-
-/**
- * Wizard page asking the user for storing an EMF Compare emfdiff file.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- *
- */
-public class ApplyWizardNewEmfdiffPage extends WizardNewFileCreationPage {
-
- private static final String FILE_EXTENSION = MPatchConstants.FILE_EXTENSION_EMF_COMPARE;
-
- public ApplyWizardNewEmfdiffPage(String pageName, IStructuredSelection selection) {
- super(pageName, selection);
- setTitle(pageName);
- setDescription("Please select a file to store the emfdiff.");
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- initialize();
- }
- }
-
- private void initialize() {
- if (getFileName() == null || getFileName().length() == 0) {
- final URI uri = ((ApplyWizard)getWizard()).getMPatch().eResource().getURI();
- final String filename = uri.lastSegment();
- setFileName(filename.substring(0, filename.lastIndexOf(".") + 1) + FILE_EXTENSION);
- }
- }
-
- @Override
- protected boolean validatePage() {
- if (super.validatePage()) {
- final String extension = new Path(getFileName()).getFileExtension();
- if (extension == null || !FILE_EXTENSION.equals(extension)) {
- setErrorMessage("Wrong file extension! '" + FILE_EXTENSION + "' expected.");
- return false;
- }
- final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
- ((ApplyWizard)getWizard()).setEmfdiff(file);
- return true;
- }
- return false;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardNewModelPage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardNewModelPage.java deleted file mode 100644 index bd9cbb84c..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardNewModelPage.java +++ /dev/null @@ -1,65 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply.wizards;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
-
-/**
- * Wizard page asking the user for storing a copy of the unchanged target model.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- *
- */
-public class ApplyWizardNewModelPage extends WizardNewFileCreationPage {
-
- public ApplyWizardNewModelPage(String pageName, IStructuredSelection selection) {
- super(pageName, selection);
- setTitle(pageName);
- setDescription("Please select a file to store a copy of the model, e.g. for reviewing the changes made to the model.");
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- initialize();
- }
- }
-
- private void initialize() {
- if (getFileName() == null || getFileName().length() == 0) {
- final URI uri = ((ApplyWizard)getWizard()).getModelResource().getURI();
-// setFileName(uri.lastSegment());
- setFileName(uri.trimFileExtension().lastSegment() + "_copy." + uri.fileExtension());
- }
- }
-
- @Override
- protected boolean validatePage() {
- if (super.validatePage()) {
- final String expectedExtension = ((ApplyWizard)getWizard()).getModelResource().getURI().fileExtension();
- final String actualExtension = new Path(getFileName()).getFileExtension();
- if (actualExtension == null || !actualExtension.equals(expectedExtension)) {
- setErrorMessage("Wrong file extension! '" + expectedExtension + "' expected (same as input model).");
- return false;
- }
- final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
- ((ApplyWizard)getWizard()).setNewModelFile(file);
- return true;
- }
- return false;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardResolvePage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardResolvePage.java deleted file mode 100644 index 34b073ee8..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardResolvePage.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.wizards; - -import java.util.List; - -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.compare.mpatch.IndepChange; -import org.eclipse.emf.compare.mpatch.MPatchModel; -import org.eclipse.emf.compare.mpatch.apply.util.MPatchResolver; -import org.eclipse.emf.compare.mpatch.apply.util.MPatchValidator; -import org.eclipse.emf.compare.mpatch.binding.MPatchModelBinding; -import org.eclipse.emf.compare.mpatch.common.util.CommonUtils; -import org.eclipse.emf.compare.mpatch.common.util.ExtensionManager; -import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants; -import org.eclipse.emf.compare.mpatch.extension.IMPatchResolution; -import org.eclipse.emf.compare.mpatch.extension.IMPatchResolutionHost; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences; -import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences.ValidationResult; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -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.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; - - -/** - * Wizard page for resolving the symbolic references of the selected {@link MPatchModel} to the target model. - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - * - */ -public class ApplyWizardResolvePage extends WizardPage implements IMPatchResolutionHost { - - /** Info text for showing to the user how the changes resolved. */ - final String INFO_TEXT = "Selected changes: %d, to be applied: %d, already applied: %d, not resolved: %d, invalid state: %d"; - - /** The model to which the diff should be applied (from a previous page). */ - private Resource modelResource; - - /** the diff itself (from a previous page). */ - private MPatchModel mpatch; - - /** The result of the symbolic reference resolution. */ - private ResolvedSymbolicReferences resolvedElements; - - /** Info label. */ - private Label infoLabel; - - /** Store intermediate models or not. */ - private Button storeIntermediateModelsCheckbox; - - /** The checkbox whether the {@link MPatchModelBinding} should be stored afterwards. */ - private Button storeBindingButton; - - /** The checkbox whether already applied changes shall be respected. */ - private Button respectAppliedButton; - - /** Adapter factory for emf model. */ - private final AdapterFactory adapterFactory; - - private final AdapterFactoryLabelProvider labelProvider; - - private IMPatchResolution iDiffResolution; - - /** - * Constructor for this wizard page. - * - * @param pageName - * The name and title of the page. - * @param diffApplier - * Instance of {@link IDiffApplier} which will be used to resolve references. - */ - public ApplyWizardResolvePage(String pageName, AdapterFactory adapterFactory) { - super(pageName); - setTitle(pageName); - setDescription("Resolve " + MPatchConstants.SYMBOLIC_REFERENCES_NAME + " for the selected model."); - this.adapterFactory = adapterFactory; - labelProvider = new AdapterFactoryLabelProvider(adapterFactory); - - iDiffResolution = ExtensionManager.getSelectedResolution(); - } - - public void createControl(Composite parent) { - final Composite container = new Composite(parent, SWT.NULL); - final GridLayout layout = new GridLayout(); - layout.numColumns = 3; - layout.verticalSpacing = 9; - container.setLayout(layout); - - // add container for external symbolic reference resolution - Group resolutionContainer = new Group(container, SWT.SHADOW_OUT); - resolutionContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); - resolutionContainer.setLayout(new GridLayout(1, false)); - resolutionContainer.setText(iDiffResolution.getLabel()); - - // add specific GUI from the extension - iDiffResolution.buildResolutionGUI(resolutionContainer, adapterFactory); - - // add some info about the resolved elements - infoLabel = new Label(container, SWT.NULL); - infoLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); - - respectAppliedButton = new Button(container, SWT.CHECK); - respectAppliedButton.setText("Detect and bind already applied changes (experimental feature)"); - respectAppliedButton.setSelection(false); // default is false - GridData gd = new GridData(); - gd.horizontalSpan = 3; - respectAppliedButton.setLayoutData(gd); - respectAppliedButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - iDiffResolution.refineResolution(resolvedElements, respectApplied(), ApplyWizardResolvePage.this); - dialogChanged(); - } - }); - - // button whether or not intermediate models should be stored - storeIntermediateModelsCheckbox = new Button(container, SWT.CHECK); - storeIntermediateModelsCheckbox.setText("Store intermediate differences and model"); - storeIntermediateModelsCheckbox.setSelection(false); // default is false - gd = new GridData(); - gd.horizontalSpan = 3; - storeIntermediateModelsCheckbox.setLayoutData(gd); - - storeBindingButton = new Button(container, SWT.CHECK); - storeBindingButton.setText("Store binding between " + MPatchConstants.MPATCH_SHORT_NAME + " and model in a file"); - storeBindingButton.setSelection(false); // default is false - gd = new GridData(); - gd.horizontalSpan = 3; - storeBindingButton.setLayoutData(gd); - setControl(container); - } - - /** - * @return Whether the user selected to store intermediate models. - */ - boolean storeIntermediateModels() { - // package visibility only such that the wizard has access to it. - return storeIntermediateModelsCheckbox.getSelection(); - } - - /** - * @return Whether the user selected to store the binding. - */ - boolean storeBinding() { - return storeBindingButton.getSelection(); - } - - /** - * @return Whether the user selected to respect already applied changes. - */ - public boolean respectApplied() { - return respectAppliedButton.getSelection(); - } - - /** - * Update input from previous pages and re-resolve symbolic references, if necessary. Then, update the viewer. - */ - public boolean resolved(ResolvedSymbolicReferences mapping) { - resolvedElements = mapping; - dialogChanged(); - return true; - } - - @Override - public void setVisible(boolean visible) { - super.setVisible(visible); - if (visible) { - final Resource modelResource = ((ApplyWizard) getWizard()).getModelResource(); - final MPatchModel mpatch = ((ApplyWizard) getWizard()).getMPatch(); - EObject modelTarget = ((ApplyWizard) getWizard()).getModelTarget(); - if (modelResource != null && mpatch != null) { - if (!modelResource.equals(this.modelResource) || !mpatch.equals(this.mpatch) || true) { - this.modelResource = modelResource; - this.mpatch = mpatch; - if (modelTarget == null) - modelTarget = modelResource.getContents().get(0); - - // do we already have a resolution for that model and that mpatch? - // if not, create new resolution - if (resolvedElements == null || !mpatch.equals(resolvedElements.getMPatchModel()) || !modelTarget.equals(resolvedElements.getModel())) { - resolvedElements = MPatchResolver.resolveSymbolicReferences(mpatch, modelTarget, - ResolvedSymbolicReferences.RESOLVE_UNCHANGED, respectApplied()); - } - - // update this page - iDiffResolution.refineResolution(resolvedElements, respectApplied(), this); - dialogChanged(); - } // else nothing changed - } else { - updateStatus("Please select a valid " + MPatchConstants.MPATCH_SHORT_NAME + " and a valid target model before."); - } - } - } - - private void updateStatus(String message) { - setErrorMessage(message); - setPageComplete(message == null); - } - - /** Notify the user if something is not right. */ - private void dialogChanged() { - final String infoText; - final String status; - if (resolvedElements != null) { - if (resolvedElements.getResolutionByChange().size() > 0) { - - // get statistics - final boolean respectApplied = respectApplied(); - final List<IndepChange> invalidResolutions = MPatchValidator.validateResolutions(resolvedElements, respectApplied); - final int unresolved = invalidResolutions.size(); - final int total = resolvedElements.getResolutionByChange().keySet().size(); - final int before = CommonUtils.filterByValue(resolvedElements.getValidation(), ValidationResult.STATE_BEFORE).size(); - final int after = CommonUtils.filterByValue(resolvedElements.getValidation(), ValidationResult.STATE_AFTER).size(); - final int invalid = CommonUtils.filterByValue(resolvedElements.getValidation(), ValidationResult.STATE_INVALID).size() - + CommonUtils.filterByValue(resolvedElements.getValidation(), ValidationResult.REFERENCE).size(); - - infoText = String.format(INFO_TEXT, total, before, after, unresolved, invalid); - - // evaluate statistics - if (unresolved == 0 && invalid == 0) { - ((ApplyWizard) getWizard()).setResolvedElements(resolvedElements); - status = null; - } else if (unresolved > 0) { - status ="Not all " + MPatchConstants.SYMBOLIC_REFERENCES_NAME + " resolved sufficiantly: " - + labelProvider.getText(invalidResolutions.get(0)); - } else { // invalid > 0 - status = "Not all changes can be applied to the selected model elements!"; - } - } else { - infoText = "Please select some changes."; - status = "No changes are selected!"; - } - } else { - infoText = "There is an error in the resolution of " + MPatchConstants.SYMBOLIC_REFERENCES_NAME + "!"; - status = "There is an error in the resolution of " + MPatchConstants.SYMBOLIC_REFERENCES_NAME + "!"; - } - infoLabel.setText(infoText); - updateStatus(status); - } - -} diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSaveBindingPage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSaveBindingPage.java deleted file mode 100644 index 393d042cf..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSaveBindingPage.java +++ /dev/null @@ -1,71 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply.wizards;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.mpatch.MPatchModel;
-import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
-
-
-/**
- * Wizard page asking the user for storing the binding between the {@link MPatchModel} and the changed target model.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- *
- */
-public class ApplyWizardSaveBindingPage extends WizardNewFileCreationPage {
-
- private static final String DIFFBINDING_EXTENSION = MPatchConstants.FILE_EXTENSION_MPATCH_BINDING;
-
- public ApplyWizardSaveBindingPage(String pageName, IStructuredSelection selection) {
- super(pageName, selection);
- setTitle(pageName);
- setDescription("Please select a file to store the binding between the " + MPatchConstants.MPATCH_SHORT_NAME
- + " and the model.");
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- initialize();
- }
- }
-
- private void initialize() {
- if (getFileName() == null || getFileName().length() == 0) {
- final URI uri = ((ApplyWizard) getWizard()).getModelResource().getURI();
- // setFileName(uri.lastSegment());
- setFileName(uri.trimFileExtension().lastSegment() + "." + DIFFBINDING_EXTENSION);
- }
- }
-
- @Override
- protected boolean validatePage() {
- if (super.validatePage()) {
- final String actualExtension = new Path(getFileName()).getFileExtension();
- if (actualExtension == null || !actualExtension.equals(DIFFBINDING_EXTENSION)) {
- setErrorMessage("Wrong file extension! '" + DIFFBINDING_EXTENSION + "' expected.");
- return false;
- }
- final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
- getContainerFullPath().append(getFileName()));
- ((ApplyWizard) getWizard()).setBindingFile(file);
- return true;
- }
- return false;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSelectMPatchPage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSelectMPatchPage.java deleted file mode 100644 index 975ac2191..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSelectMPatchPage.java +++ /dev/null @@ -1,189 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply.wizards;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.ui.dialogs.ResourceDialog;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.mpatch.MPatchModel;
-import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants;
-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.emf.edit.ui.provider.AdapterFactoryLabelProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.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.Label;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * Wizard page for selecting a {@link MPatchModel} from the workspace.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- */
-public class ApplyWizardSelectMPatchPage extends WizardPage {
-
- /** The uri of the selected file. */
- private URI uri;
-
- /** The text element on the page to display the uri. */
- private Text uriText;
-
- /** A viewer for presenting the content of the input. */
- private TreeViewer viewer;
-
- /** Adapter factory for emf model. */
- private final AdapterFactory adapterFactory;
-
- /**
- * Constructor for this wizard page.
- *
- * @param pageName
- * The name and title of this particular page.
- * @param file
- * The default filename which can be provided.
- */
- public ApplyWizardSelectMPatchPage(String pageName, IFile file, AdapterFactory adapterFactory) {
- super(pageName);
- if (file != null) {
- uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
- }
- setTitle(pageName);
- setDescription("Select " + MPatchConstants.MPATCH_LONG_NAME);
- this.adapterFactory = adapterFactory;
- }
-
- public void createControl(Composite parent) {
- final Composite container = new Composite(parent, SWT.NULL);
- final GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 3;
- layout.verticalSpacing = 9;
- final Label label = new Label(container, SWT.NULL);
- label.setText("&" + MPatchConstants.MPATCH_LONG_NAME + ":");
-
- uriText = new Text(container, SWT.BORDER | SWT.SINGLE);
- final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- uriText.setLayoutData(gd);
- // uriText.setEditable(false);
- uriText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- dialogChanged();
- }
- });
-
- final Button button = new Button(container, SWT.PUSH);
- button.setText("B&rowse...");
- button.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleBrowse();
- }
- });
-
- final GridData gd1 = new GridData(GridData.FILL_HORIZONTAL);
- gd1.horizontalSpan = 3;
- final Label infoLabel = new Label(container, SWT.NULL);
- infoLabel.setLayoutData(gd1);
- infoLabel.setText("Contents of the selected resource:");
- final GridData gd2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
- gd2.horizontalSpan = 3;
- gd2.grabExcessHorizontalSpace = true;
- gd2.grabExcessVerticalSpace = true;
-
- viewer = new TreeViewer(container, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- viewer.getTree().setLayoutData(gd2);
- viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
- viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
-
- initialize();
- // dialogChanged(); // is already called because of notifiers!
- setControl(container);
- }
-
- /**
- * Set the uri as the default input.
- */
- private void initialize() {
- if (uri != null && uriText.getText().length() == 0) {
- uriText.setText(uri.toString());
- } else {
- uriText.setText("");
- }
- }
-
- /**
- * Ask user to select an mpatch from the workspace.
- */
- private void handleBrowse() {
- final ResourceDialog dialog = new ResourceDialog(getShell(), "Select "
- + MPatchConstants.MPATCH_LONG_NAME, SWT.OPEN | SWT.SINGLE);
- if (dialog.open() == Window.OK) {
- if (dialog.getURIs().size() >= 1) {
- uri = dialog.getURIs().get(0);
- uriText.setText(uri.toString());
- } else {
- uri = null;
- uriText.setText("");
- }
- }
- }
-
- private void updateStatus(String message) {
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-
- /**
- * Get the selected file, check whether it is ok and present its content to the user via the tree viewer.
- * Print an appropriate error message if the input is incorrect.
- */
- private void dialogChanged() {
- final String fileUri = uriText.getText().trim();
- viewer.setInput(null);
- if (fileUri.length() > 0) {
-
- try {
- uri = URI.createURI(fileUri);
- final ResourceSet resourceSet = new ResourceSetImpl();
- final Resource diffResource = resourceSet.getResource(uri, true);
- if (diffResource.getContents().get(0) instanceof MPatchModel) {
- final MPatchModel mpatch = (MPatchModel)diffResource.getContents().get(0);
- ((ApplyWizard)getWizard()).setMPatch(mpatch);
- viewer.setInput(diffResource);
- updateStatus(null);
- } else {
- updateStatus("The selected resource does not contain valid "
- + MPatchConstants.MPATCH_LONG_NAME + "!");
- uri = null;
- }
- } catch (final RuntimeException e) {
- updateStatus("Exception loading resource: " + e.getMessage() + " " + e.getStackTrace()[0]
- + "...");
- }
- } else {
- updateStatus("Please select an input file.");
- }
- }
-
-}
diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSelectModelPage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSelectModelPage.java deleted file mode 100644 index 51efbbc34..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSelectModelPage.java +++ /dev/null @@ -1,291 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Technical University of Denmark. - * 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: - * Patrick Koenemann, DTU Informatics - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.mpatch.apply.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.ui.dialogs.ResourceDialog; -import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.compare.mpatch.MPatchModel; -import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.DynamicEObjectImpl; -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.emf.edit.ui.provider.AdapterFactoryLabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * A wizard page for selecting an arbitrary emf model file to which the {@link MPatchModel} should be applied. - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ -public class ApplyWizardSelectModelPage extends WizardPage implements ISelectionChangedListener { - - /** The uri of the selected file. */ - private URI uri; - - /** The text widget which is used to present the file uri to the user. */ - private Text uriText; - - /** A viewer to present the content of the selected file to the user. */ - private TreeViewer viewer; - - /** Adapter factory for emf model. */ - private final AdapterFactory adapterFactory; - - /** - * The constructor of this page. - * - * @param pageName - * The name and title of this page. - */ - public ApplyWizardSelectModelPage(String pageName, URI modelURI, AdapterFactory adapterFactory) { - super(pageName); - uri = modelURI; - setTitle(pageName); - setDescription("Select a model to which the " + MPatchConstants.MPATCH_SHORT_NAME - + " should be applied."); - this.adapterFactory = adapterFactory; - } - - public void createControl(Composite parent) { - final Composite container = new Composite(parent, SWT.NULL); - final GridLayout layout = new GridLayout(); - container.setLayout(layout); - layout.numColumns = 3; - layout.verticalSpacing = 9; - final Label label = new Label(container, SWT.NULL); - label.setText("&Target model:"); - - uriText = new Text(container, SWT.BORDER | SWT.SINGLE); - final GridData gd = new GridData(GridData.FILL_HORIZONTAL); - uriText.setLayoutData(gd); - // uriText.setEditable(false); - uriText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - dialogChanged(); - } - }); - - final Button button = new Button(container, SWT.PUSH); - button.setText("B&rowse..."); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - handleBrowse(); - } - }); - - final GridData gd1 = new GridData(GridData.FILL_HORIZONTAL); - gd1.horizontalSpan = 3; - final Label infoLabel = new Label(container, SWT.NULL); - infoLabel.setLayoutData(gd1); - infoLabel.setText("Contents of the selected resource:"); - final GridData gd2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); - gd2.horizontalSpan = 3; - gd2.grabExcessHorizontalSpace = true; - gd2.grabExcessVerticalSpace = true; - - viewer = new TreeViewer(container, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - viewer.getTree().setLayoutData(gd2); - viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); - viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); - viewer.addSelectionChangedListener(this); - - final GridData gd3 = new GridData(GridData.FILL_HORIZONTAL); - gd3.horizontalSpan = 3; - final Label hintLabel = new Label(container, SWT.WRAP); - hintLabel.setLayoutData(gd3); - hintLabel.setText("Hint: You may also select a sub-model that contains ALL RELEVANT ELEMENTS for " - + MPatchConstants.MPATCH_SHORT_NAME + " application (improves performance)."); - - initialize(); - dialogChanged(); - setControl(container); - } - - /** - * Set the uri as the default input. - */ - private void initialize() { - if (uri != null && uriText.getText().length() == 0) { - uriText.setText(uri.toString()); - } else { - final URI diffURI = ((ApplyWizard)getWizard()).getMPatch().eResource().getURI(); - uriText.setText(diffURI.toString().substring(0, - diffURI.toString().length() - diffURI.lastSegment().length())); - } - } - - /** - * Ask user to select an emf model file from the workspace. - */ - private void handleBrowse() { - final ResourceDialog dialog = new ApplyToResourceDialog(getShell(), "Select model", SWT.OPEN - | SWT.SINGLE); - if (dialog.open() == Window.OK) { - if (dialog.getURIs().size() >= 1) { - uri = dialog.getURIs().get(0); - uriText.setText(uri.toString()); - } else { - uri = null; - uriText.setText(""); - } - } - } - - private void updateStatus(String message) { - setErrorMessage(message); - setPageComplete(message == null); - } - - /** - * Get the selected file, check whether it is ok and present its content to the user via the tree viewer. - * Print an appropriate error message if the input is not an emf model. - */ - private void dialogChanged() { - final String fileUri = uriText.getText().trim(); - viewer.setInput(null); - if (fileUri.length() > 0) { - - try { - uri = URI.createURI(fileUri); - final ResourceSet resourceSet = new ResourceSetImpl(); - final Resource modelResource = resourceSet.getResource(uri, true); - if (modelResource.getContents().size() != 1) { - - /* - * Special case in RSA: instances of DynamicEObject are further root objects which store - * some documentation on the model. Assuming that a model conforms to a specific meta - * model, we can generalize this setting and ignore all dynamic EObjects here. - */ - int counter = 0; - for (EObject obj : modelResource.getContents()) { - if (!(obj instanceof DynamicEObjectImpl)) { - counter++; - } - } - viewer.setInput(modelResource); - if (counter > 1) { - updateStatus("At the moment, only one root object is allowed!"); - uri = null; - return; - } else if (counter == 1) { - // safe! :-D - } else if (counter == 0) { - updateStatus("Only dynamic objects found in model - please make sure that your model conforms to a registered meta model!"); - uri = null; - return; - } - } - - if (modelResource.getContents().get(0) instanceof EObject) { - ((ApplyWizard)getWizard()).setModelResource(modelResource); - viewer.setInput(modelResource); - } else { - updateStatus("The selected resource does not contain a valid model!"); - uri = null; - return; - } - } catch (final RuntimeException e) { - updateStatus("Exception loading resource: " + e.getMessage() + " " + e.getStackTrace()[0] - + "..."); - return; - } - - updateStatus(null); - } else { - updateStatus("Please select an input file."); - } - } - - public void selectionChanged(SelectionChangedEvent event) { - final ISelection selection = event.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection)selection; - if (structuredSelection.size() == 1) { - final Object obj = structuredSelection.getFirstElement(); - if (obj instanceof EObject) { - ((ApplyWizard)getWizard()).setModelTarget((EObject)obj); - } - } - } - } - - /** - * Resource dialog with suggested path. - * - * @author Patrick Koenemann (pk@imm.dtu.dk) - */ - private final class ApplyToResourceDialog extends ResourceDialog { - private ApplyToResourceDialog(Shell parent, String title, int style) { - super(parent, title, style); - } - - @Override - protected Control createDialogArea(Composite parent) { - final Composite composite = (Composite)super.createDialogArea(parent); - uriField.setText(ApplyWizardSelectModelPage.this.uriText.getText()); - return composite; - } - - @Override - protected void prepareBrowseWorkspaceButton(Button browseWorkspaceButton) { - browseWorkspaceButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - // FIXME: Unfortunately the dialog does not recognize our default selection :-( - IFile[] iFiles = new IFile[0]; - try { - iFiles = new IFile[] {ResourcesPlugin.getWorkspace().getRoot() - .getFile(new Path(uriField.getText())),}; - } catch (Exception e) { - // Ignore - } - final IFile[] files = WorkspaceResourceDialog.openFileSelection(getShell(), - "Apply differences to...", null, false, iFiles, null); - if (files.length != 0) { - final IFile file = files[0]; - if (file != null) { - uriField.setText(URI.createPlatformResourceURI(file.getFullPath().toString(), - true).toString()); - } - } - } - }); - } - } -} diff --git a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSummaryPage.java b/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSummaryPage.java deleted file mode 100644 index f037438e0..000000000 --- a/plugins/org.eclipse.emf.compare.mpatch.apply/src/org/eclipse/emf/compare/mpatch/apply/wizards/ApplyWizardSummaryPage.java +++ /dev/null @@ -1,219 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 Technical University of Denmark.
- * 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:
- * Patrick Koenemann, DTU Informatics - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.mpatch.apply.wizards;
-
-import java.util.LinkedList;
-import java.util.Queue;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.mpatch.ChangeGroup;
-import org.eclipse.emf.compare.mpatch.IndepChange;
-import org.eclipse.emf.compare.mpatch.MPatchModel;
-import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants;
-import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-
-
-/**
- * A wizard page for summarizing the information the wizard collected.
- *
- * @author Patrick Koenemann (pk@imm.dtu.dk)
- *
- */
-public class ApplyWizardSummaryPage extends WizardPage {
-
- /** The text widget for presenting the diff uri. */
- private Text diffUriText;
-
- /** The text widget for presenting the model uri. */
- private Text modelUriText;
-
- /** The text widget for presenting the uri of the new model uri. */
- private Text newModelUriText;
-
- /** The text widget for presenting the emfdiff uri. */
- private Text emfdiffUriText;
-
- /** The text widget for presenting the binding uri. */
- private Text bindingUriText;
-
- /** The label widget for presenting the summary of resolved references. */
- private Label resolvedLabel;
-
- /** The checkbox whether the result should be shown with EMF Compare afterwards. */
- private Button reviewDiffApplicationButton;
-
- /** Default text for the resolvedLabel label. */
- private static final String RESOLVED_LABEL_TEXT = " changes are selected.";
-
- /**
- * Constructor for this page.
- *
- * @param pageName
- * The name and title of the page.
- */
- public ApplyWizardSummaryPage(String pageName) {
- super(pageName);
- setTitle(pageName);
- setDescription("Select a place where the information is stored.");
- }
-
- public void createControl(Composite parent) {
- final Composite container = new Composite(parent, SWT.NULL);
- final GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 2;
- layout.verticalSpacing = 9;
-
- new Label(container, SWT.NULL).setText(MPatchConstants.MPATCH_LONG_NAME + ":");
- diffUriText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- diffUriText.setLayoutData(gd);
- diffUriText.setEditable(false);
-
- new Label(container, SWT.NULL).setText("Apply to model:");
- modelUriText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- modelUriText.setLayoutData(gd);
- modelUriText.setEditable(false);
-
- new Label(container, SWT.NULL).setText("Save new model:");
- newModelUriText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- newModelUriText.setLayoutData(gd);
- newModelUriText.setEditable(false);
-
- new Label(container, SWT.NULL).setText("Save emfdiff:");
- emfdiffUriText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- emfdiffUriText.setLayoutData(gd);
- emfdiffUriText.setEditable(false);
-
- new Label(container, SWT.NULL).setText("Save binding:");
- bindingUriText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- bindingUriText.setLayoutData(gd);
- bindingUriText.setEditable(false);
-
- new Label(container, SWT.NULL).setText("Reference resolution:");
- resolvedLabel = new Label(container, SWT.NULL);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- resolvedLabel.setLayoutData(gd);
-
- reviewDiffApplicationButton = new Button(container, SWT.CHECK);
- reviewDiffApplicationButton.setText("Review result with EMF Compare");
- reviewDiffApplicationButton.setSelection(true); // default is true
- gd = new GridData();
- gd.horizontalSpan = 2;
- reviewDiffApplicationButton.setLayoutData(gd);
-
- initialize();
- setControl(container);
-
- // page must at least be visited once before it is set to complete
- setPageComplete(false);
- }
-
- /**
- * Collect the information from all other pages and present it to the user. In the end, the dialog is checked using
- * {@link ApplyWizardSummaryPage#dialogChanged()}.
- */
- private void initialize() {
- final EObject diff = ((ApplyWizard) getWizard()).getMPatch();
- final Resource model = ((ApplyWizard) getWizard()).getModelResource();
- final IFile newModelFile = ((ApplyWizard) getWizard()).getNewModelFile();
- final IFile emfdiffFile = ((ApplyWizard) getWizard()).getEmfdiffFile();
- final IFile bindingFile = ((ApplyWizard) getWizard()).getBindingFile();
- final ResolvedSymbolicReferences resolved = ((ApplyWizard) getWizard()).getResolvedElements();
- newModelUriText.setEnabled(((ApplyWizard) getWizard()).saveIntermediateFiles);
- emfdiffUriText.setEnabled(((ApplyWizard) getWizard()).saveIntermediateFiles);
- bindingUriText.setEnabled(((ApplyWizard) getWizard()).saveBinding);
- diffUriText.setText(diff == null ? "" : diff.eResource().getURI().toString());
- modelUriText.setText(model == null ? "" : model.getURI().toString());
- if (((ApplyWizard) getWizard()).saveIntermediateFiles) {
- newModelUriText.setText(newModelFile == null ? "" : URI.createPlatformResourceURI(
- newModelFile.getFullPath().toString(), true).toString());
- emfdiffUriText.setText(emfdiffFile == null ? "" : URI.createPlatformResourceURI(
- emfdiffFile.getFullPath().toString(), true).toString());
- }
- if (((ApplyWizard) getWizard()).saveBinding) {
- bindingUriText.setText(bindingFile == null ? "" : URI.createPlatformResourceURI(
- bindingFile.getFullPath().toString(), true).toString());
- }
- resolvedLabel.setText(resolved == null ? "" : resolved.getResolutionByChange().keySet().size() + " / "
- + countChanges(resolved.getMPatchModel()) + " " + RESOLVED_LABEL_TEXT);
-
- dialogChanged();
- }
-
- private int countChanges(MPatchModel mpatch) {
- int counter = 0;
- Queue<IndepChange> queue = new LinkedList<IndepChange>();
- queue.addAll(mpatch.getChanges());
- while (!queue.isEmpty()) {
- IndepChange change = queue.poll();
- if (change instanceof ChangeGroup) {
- queue.addAll(((ChangeGroup) change).getSubChanges());
- } else
- counter++;
- }
- return counter;
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (visible) {
- initialize();
- }
- }
-
- private void updateStatus(String message) {
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-
- boolean reviewDiffApplication() {
- return reviewDiffApplicationButton.getSelection();
- }
-
- /**
- * Set status and notify user if something is wrong.
- */
- private void dialogChanged() {
- // just a last check if all fields are set
- if (diffUriText.getText().trim().length() == 0) {
- updateStatus(MPatchConstants.MPATCH_SHORT_NAME + " is not set!");
- } else if (modelUriText.getText().trim().length() == 0) {
- updateStatus("Model is not set!");
- } else if (((ApplyWizard) getWizard()).saveIntermediateFiles
- && emfdiffUriText.getText().trim().length() == 0) {
- updateStatus("Emfdiff is not set!");
- } else if (((ApplyWizard) getWizard()).saveIntermediateFiles
- && newModelUriText.getText().trim().length() == 0) {
- updateStatus("New model is not set!");
- } else if (((ApplyWizard) getWizard()).saveBinding && bindingUriText.getText().trim().length() == 0) {
- updateStatus("Binding file is not set!");
- } else {
- updateStatus(null);
- }
- }
-}
|