Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c14b6101d5872523204d647ad90742118e7ef21f (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
99
100
101
102
103
104
105
106
107
108
109
110
/*****************************************************************************
 * 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.properties.runtime.view;

import java.util.Collections;
import java.util.List;

import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.view.constraints.IConstraintDescriptor;
import org.eclipse.papyrus.properties.runtime.view.content.ContainerDescriptor;
import org.eclipse.swt.graphics.Image;
import org.w3c.dom.Node;


/**
 * descriptor for fragments
 */
public class FragmentDescriptor extends AbstractConstrainedDescriptor implements IFragmentDescriptor {

	/** list of containers created by this dialog */
	protected List<ContainerDescriptor> descriptors;

	/**
	 * Creates a new FragmentDescriptor.
	 * 
	 * @param id
	 *        the identifier of the fragment
	 * @param constraints
	 *        the list of constraints to be verified when the fragment is to be displayed
	 * @param descriptors
	 *        list of containers in this fragment
	 * @param selectionSize
	 *        the size of the selection for which this fragment is valid
	 */
	public FragmentDescriptor(String id, List<IConstraintDescriptor> constraints, List<ContainerDescriptor> descriptors, int selectionSize) {
		super(id, constraints, selectionSize);
		this.descriptors = descriptors;
	}

	/**
	 * Creates a new FragmentDescriptor.
	 * 
	 * @param id
	 *        the identifier of the fragment
	 * @param constraints
	 *        the list of constraints to be verified when the fragment is to be displayed
	 * @param contentNode
	 *        the node configuring this fragment descriptor
	 * @param selectionSize
	 *        the size of the selection for which this fragment is valid
	 * @param parser
	 *        the parser used to parse the configuration node
	 */
	public FragmentDescriptor(String id, List<IConstraintDescriptor> constraints, Node contentNode, int selectionSize, PropertyViewProviderParser parser) {
		super(id, constraints, contentNode, selectionSize, parser);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<ContainerDescriptor> getContainerDescriptors() {
		if(unparsed && !parseFailed) {
			if(parser == null) {
				descriptors = Collections.emptyList();
				Activator.log.error("No parser was given to the view descriptor " + id, null);
				parseFailed = true;
			} else {
				try {
					descriptors = parser.parseFragmentContentNode(contentNode);
					parseFailed = false;
				} catch (XMLParseException e) {
					Activator.log.error(e);
					parseFailed = true;
				}
			}
		}
		return descriptors;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getText() {
		return "Fragment: " + getId();
	}

	/**
	 * {@inheritDoc}
	 */
	public Image getImage() {
		return Activator.getImage("/icons/Fragment.gif");
	}

	/**
	 * {@inheritDoc}
	 */
	public FragmentDescriptorState createState(boolean readOnly) {
		return new FragmentDescriptorState(this, readOnly);
	}

}

Back to the top