Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 72e165ad098c5b992c5a50f47d17a7bd32e7fa3b (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
/*****************************************************************************
 * Copyright (c) 2010 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:
 *  Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.infra.services.validation.commands;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.ui.dialogs.PreferencesUtil;


public class SelectAndValidateModelCommand extends AbstractValidateCommand {

	public SelectAndValidateModelCommand(EObject selectedElement) {
		super("Validate subtree", TransactionUtil.getEditingDomain(selectedElement), selectedElement);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

		String idRootPage = "org.eclipse.emf.validation.ui.rootPage";
		String idConstraints = "org.eclipse.emf.validation.constraintsPrefs";
		String filter[] = {
			idRootPage,
			idConstraints
		};
		PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, idConstraints, filter, null);
		int result = dialog.open();

		if(result == IDialogConstants.OK_ID) {
			EObject selectedObject = selectedElement;
			// replace selection by model instead of current selection
			while(selectedObject.eContainer() != null) {
				selectedObject = selectedObject.eContainer();
			}
			Resource resource = getResource();
			if ((resource != null) && (eclipseResourcesUtil != null)) {
				eclipseResourcesUtil.deleteMarkers(getResource());
			}
			runValidation(selectedObject);
		}
		return null;
	}
}

Back to the top