Skip to main content
summaryrefslogtreecommitdiffstats
blob: 12897e6d940bfb9cad467bfd4a524fe92be2cb1b (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*******************************************************************************
 * Copyright (c) 2011 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.logical.synchronization;

import java.io.IOException;
import java.util.Collections;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.compare.logical.model.EMFModelProvider;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.ui.mapping.SaveableComparison;

/**
 * Instances of this class will be used to buffer the changes made to the EMF logical models during a
 * comparison and determine when a save is needed.
 * 
 * @author <a href="mailto:laurent.goubet@obeo.fr">laurent Goubet</a>
 */
public class EMFSaveableBuffer extends SaveableComparison {
	/** Cache key for the logical model buffer within the synchronization cache. */
	public static final String SYNCHRONIZATION_CACHE_KEY = EMFModelProvider.PROVIDER_ID + ".sync.cache"; //$NON-NLS-1$

	/** Human-readable name of this saveable. */
	private final String name;

	/** Resource set which contains the actual models. */
	private final ResourceSet resourceSet;

	/**
	 * Creates our buffer given its human-readable name and its underlying resource set.
	 * 
	 * @param name
	 *            Human-readable name of this saveable.
	 * @param resourceSet
	 *            Resource set which contains the actual models.
	 */
	public EMFSaveableBuffer(String name, ResourceSet resourceSet) {
		this.name = name;
		this.resourceSet = resourceSet;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.team.ui.mapping.SaveableComparison#performSave(org.eclipse.core.runtime.IProgressMonitor)
	 */
	@Override
	protected void performSave(IProgressMonitor monitor) throws CoreException {
		for (Resource resource : resourceSet.getResources()) {
			try {
				resource.save(Collections.emptyMap());
			} catch (IOException e) {
				// FIXME provide feedback
			}
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.team.ui.mapping.SaveableComparison#performRevert(org.eclipse.core.runtime.IProgressMonitor)
	 */
	@Override
	protected void performRevert(IProgressMonitor monitor) {
		// FIXME how can we revert changes made to this logical model?
		// for (Resource resource : resourceSet.getResources()) {
		// resource.unload();
		// }
		// EcoreUtil.resolveAll(resourceSet);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.Saveable#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.Saveable#getToolTipText()
	 */
	@Override
	public String getToolTipText() {
		return getName();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.Saveable#getImageDescriptor()
	 */
	@Override
	public ImageDescriptor getImageDescriptor() {
		// FIXME where is this displayed when non-null?
		return null;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.Saveable#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object object) {
		return object instanceof EMFSaveableBuffer && name.equals(((EMFSaveableBuffer)object).name)
				&& resourceSet.equals(((EMFSaveableBuffer)object).resourceSet);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.Saveable#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int hashCode = prime * name.hashCode();
		hashCode += prime * resourceSet.hashCode();
		return hashCode;
	}
}

Back to the top