Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4032cb5acf71ecdd9f2fa6dd200e4935be876a87 (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
/*****************************************************************************
 * 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:
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.wizards.kind;

import java.util.Collection;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint;
import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;

/**
 * The ContentProvider for DiagramCategory table.
 * Returns available diagram kinds for the given diagram category(ies).
 * @since 3.0
 */
public class RepresentationKindContentProvider implements IStructuredContentProvider {

	/**
	 * Input changed.
	 *
	 * @param viewer
	 *            the viewer
	 * @param oldInput
	 *            the old input
	 * @param newInput
	 *            the new input
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}

	/**
	 * Gets the elements.
	 *
	 * @param inputElement
	 *            the input element
	 * @return the elements
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 */
	public Object[] getElements(Object inputElement) {
		ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
		if (inputElement instanceof Object[]) {
			Set<RepresentationKind> result = new TreeSet<RepresentationKind>(new Comparator<RepresentationKind>() {
				@Override
				public int compare(RepresentationKind o1, RepresentationKind o2) {
					return o1.getName().compareTo(o2.getName());
				}
			});
			for (Object next : (Object[]) inputElement) {
				if (next instanceof String) {
					String viewpointId = (String) next;
					MergedArchitectureViewpoint viewpoint = manager.getArchitectureViewpointById(viewpointId);
					result.addAll(viewpoint.getRepresentationKinds());
				}
			}
			return result.toArray(new Object[result.size()]);
		}
		if (inputElement instanceof String) {
			String viewpointId = (String) inputElement;
			MergedArchitectureViewpoint viewpoint = manager.getArchitectureViewpointById(viewpointId);
			Collection<RepresentationKind> result = viewpoint.getRepresentationKinds();
			return result.toArray(new Object[result.size()]);
		}
		return null;
	}

}

Back to the top