Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8e76f40ad1ed3f61c755b4fa889627b658460275 (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
/*****************************************************************************
 * Copyright (c) 2012 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:
 *  Saadia DHOUIB (CEA LIST) - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.export.util;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.uml.export.Activator;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Profile;


// TODO: Auto-generated Javadoc
/**
 * The Class AreThereAppliedProfilesFromWS.
 */
public class AreThereAppliedProfilesFromWS extends PropertyTester {

	/** The Constant ARE_THERE_APPLIED_PROFILES. */
	public final static String ARE_THERE_APPLIED_PROFILES = "AreThereAppliedProfiles";



	/**
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
	 * 
	 * @param receiver
	 * @param property
	 * @param args
	 * @param expectedValue
	 * @return
	 */

	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {

		// Ensure Papyrus is the active editor

		IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		if((editor == null) || (!(editor instanceof IMultiDiagramEditor))) {
			return false;
		}
		Object currentValue = null;
		if(ARE_THERE_APPLIED_PROFILES.equals(property)) {

			ServicesRegistry registry = ((IMultiDiagramEditor)editor).getServicesRegistry();
			UmlModel openedModel;
			try {
				openedModel = (UmlModel)ServiceUtils.getInstance().getModelSet(registry).getModel(UmlModel.MODEL_ID);
				EObject root = openedModel.lookupRoot();
				Object[] profiles = ProfileUtil.getAppliedProfilesFromWS(root);

				for(int i = 0; i < profiles.length; i++) {
					if(profiles[i] instanceof Profile) {
						currentValue = true;
						break;
					}
				}
				return (currentValue == expectedValue);
			} catch (ServiceException e) {
				Activator.log.error(e);
			} catch (NotFoundException e) {
				Activator.log.error(e);
			}

		}

		return false;
	}



}

Back to the top