Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 239a19a2efd77cdd96da3b8bd73a1201a4423885 (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
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;

import java.util.Collection;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;

/**
 *
 * Command to remove all styleSheets from the resource.
 *
 * @author Mickael ADAM
 *
 */
public class RemoveAllModelStyleSheetValueCommand extends RecordingCommand {

	/** The values. */
	private Collection<?> values;

	/** The resource. */
	private Resource resource;

	/** The domain. */
	private TransactionalEditingDomain domain;

	/**
	 * Constructor.
	 *
	 * @param domain
	 *            the domain
	 * @param resource
	 *            the resource
	 * @param values
	 *            the values
	 */
	public RemoveAllModelStyleSheetValueCommand(TransactionalEditingDomain domain, Resource resource, Collection<?> values) {
		super(domain);
		this.resource = resource;
		this.values = values;
		this.domain = domain;
	}

	/**
	 * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
	 *
	 */
	@Override
	public void doExecute() {
		for (Object value : values) {
			if (value instanceof StyleSheetReference) {
				StyleSheetReference styleSheet = (StyleSheetReference) value;

				// Create a request to delete the styleSheet
				DestroyElementRequest request = new DestroyElementRequest(domain, styleSheet, false);
				// Get the command to delete the styleSheet
				DestroyElementCommand command = new DestroyElementCommand(request);
				try {
					// execute command
					command.execute(new NullProgressMonitor(), null);
				} catch (ExecutionException e) {
					e.printStackTrace();
				}
			}
		}
	}

}

Back to the top