Skip to main content
summaryrefslogtreecommitdiffstats
blob: 867c1c28772d4fbf70d402034faf0d8215dd07fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2016-2017, Thales Global Services S.A.S.
 * 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:
 *   Abel Hegedus, Tamas Borbas, Balazs Grill, Peter Lunk, Daniel Segesdi (IncQuery Labs Ltd.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.diffmerge.patch.ui.utils

import org.eclipse.emf.diffmerge.patch.AttributeEntry
import org.eclipse.emf.diffmerge.patch.ElementEntry
import org.eclipse.emf.diffmerge.patch.ReferenceEntry
import org.eclipse.emf.diffmerge.patch.api.ChangeDirection
import org.eclipse.emf.diffmerge.patch.api.Identifiable
import org.eclipse.emf.diffmerge.patch.api.ModelPatchEntry
import org.eclipse.emf.diffmerge.patch.StructuralFeatureEntry

class DescriptiveEntryLabelProvider extends DefaultEntryLabelProvider {

  override getLabel(ModelPatchEntry entry) {
    return entry.shortPrettyPrint
  }

  private dispatch def String shortPrettyPrint(ModelPatchEntry entry) '''«entry.direction» «entry.entryType» «IF entry.direction==ChangeDirection.ADD»TO«ELSE»FROM«ENDIF» «entry.context.identifier»'''
  private dispatch def String shortPrettyPrint(ElementEntry entry) '''«entry.direction.decodeDirectionLabel(true).toFirstUpper» '«entry.context.identifier»' (type: '«entry.type.typeString»')'''
  private dispatch def String shortPrettyPrint(AttributeEntry entry) {
    if(entry.index==null || !entry.index.present) {
      return '''«entry.direction.decodeDirectionLabel(false).toFirstUpper» '«entry.feature.featureString»' attribute of '«entry.context.identifier»' «IF entry.direction==ChangeDirection.ADD»to '«entry.value»'«ELSE»(old value: «entry.value»)«ENDIF»'''
    } else {
      return '''«entry.direction.decodeDirectionLabel(true).toFirstUpper» '«entry.value»' value «entry.direction.toFrom» the '«entry.feature.featureString»' «entry.listEnding»'''
    }
  }
  private dispatch def String shortPrettyPrint(ReferenceEntry entry) {
    if(entry.index==null || !entry.index.present) {
      return '''«entry.direction.decodeDirectionLabel(false).toFirstUpper» '«entry.feature.featureString»' reference of '«entry.context.identifier»'«IF entry.direction==ChangeDirection.ADD» to '«entry.target.identifier»'«ELSE» (old target: '«entry.target.identifier»')«ENDIF»'''
    } else {
      return '''«entry.direction.decodeDirectionLabel(true).toFirstUpper» reference to '«entry.target.identifier»' «entry.direction.toFrom» the '«entry.feature.featureString»' «entry.listEnding»'''
    }
  }

  def String getListEnding(StructuralFeatureEntry entry) '''list of '«entry.context.identifier»' (index: «entry.index.get»)'''

  private def String decodeDirectionLabel(ChangeDirection direction, boolean isAddRemove) {
    if(isAddRemove) {
      if(direction==ChangeDirection.ADD) {
        return "add"
      } else {
        return "remove"
      }
    } else {
      if(direction==ChangeDirection.ADD) {
        return "set"
      } else {
        return "unset"
      }
    }
  }

  private def String toFrom(ChangeDirection direction) {
    if(direction==ChangeDirection.ADD) {
      return "to"
    } else {
      return "from"
    }
  }

  private def getTypeString(Identifiable identifiable) {
    return identifiable.identifier//.split('#').last
  }

  private def String getFeatureString(Identifiable identifiable) {
    return identifiable.identifier//.split("#").last.split(Pattern.quote(".")).last
  }
}

Back to the top