Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 84819b1fce0722423033d13843e02c939eb0d1f9 (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
90
91
92
93
94
95
96
97
98
/*****************************************************************************
 * Copyright (c) 2008 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:
 *  Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
 *  Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.properties.profile.ui.items;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.uml.profile.Message;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.uml2.uml.Property;



/**
 * The Class CompositeItems.
 */
public class CompositeItems {

	/**
	 * The Constructor.
	 *
	 * @param table
	 *            the table
	 * @param value
	 *            the value
	 * @param property
	 *            the property
	 */
	public CompositeItems(Table table, Property property, Object value) {

		// Checking rule
		if (property.getLower() > 0) {
			Message.error(
					"Property of type Stereotype and multiplicity lower value != 0.\n"
							+ " The profile is ill formed !");
		}

		if (property.isMultivalued()) { // property is multivalued
			final List propValues = (List) value;

			for (int i = 0; i < propValues.size(); i++) {
				createItem(table, property, propValues.get(i));
			}

		} else { // property is not multivalued

			// if the property has a value
			if (value != null) {
				createItem(table, property, value);
			}
		}
	}

	/**
	 * Creates a new item for current objet int the table.
	 *
	 * @param table
	 *            the table
	 * @param object
	 *            the object
	 * @param property
	 *            the property
	 */
	private void createItem(Table table, Property property, Object object) {

		EObject eObject = null;

		// Prepare Item data
		if (object instanceof EObject) {
			eObject = (EObject) object;

		} else { // Error
			String err = "Type " + object.toString() + " of Property " + property.getName() + " is not an EObject.";
			Message.error(err);
		}

		if (eObject != null) {
			// Prepare Item label
			TableItem propValueItem = new TableItem(table, SWT.NONE);
			propValueItem.setText(eObject.getClass().getName());
			propValueItem.setData(eObject);
		}
	}
}

Back to the top