Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 76a96fba5ecbb141534963d7525121e7b10f2257 (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
/*****************************************************************************
 * 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:
 *	Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
 *****************************************************************************/

package org.eclipse.papyrus.sysml.diagram.blockdefinition.ui;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.papyrus.sysml.portandflows.FlowSpecification;
import org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog;
import org.eclipse.papyrus.uml.diagram.common.util.Visitor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.util.UMLUtil;

/**
 * <pre>
 * This class provides a Dialog to manage easily the provided and 
 * the required Interfaces for a {@link Port}.
 * </pre>
 */
public class BlockDefinitionInterfaceManagerDialog extends InterfaceManagerDialog {


	/**
	 * Instantiates a new block definition interface manager dialog.
	 *
	 * @param parentShell
	 *        the parent shell
	 * @param port
	 *        the port
	 */
	public BlockDefinitionInterfaceManagerDialog(Shell parentShell, Port port) {
		super(parentShell, port);

	}


	/**
	 * Gets the all available interfaces.
	 *
	 * @param pack
	 *        the pack
	 * @return the all available interfaces
	 * @see org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog#getAllAvailableInterfaces(org.eclipse.uml2.uml.Package)
	 */
	protected List<Interface> getAllAvailableInterfaces(Package pack) {
		Set<Interface> otherInterfaces = new HashSet<Interface>();
		List<Element> interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class);
		for(Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) {
			interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class));

		}

		for(Element element : interfaces) {
			// Test if the interface is a FlowSpecification
			FlowSpecification flowSpec = UMLUtil.getStereotypeApplication(element, FlowSpecification.class);
			if(flowSpec == null) {
				otherInterfaces.add((Interface)element);
			}
		}

		return Arrays.asList(otherInterfaces.toArray(new Interface[otherInterfaces.size()]));
	}


}

Back to the top