Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ddfb19d6ec0143177ada11db07b1afa86abd52de (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*****************************************************************************
 * Copyright (c) 2017 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
 *  Micka�l ADAM (ALL4TEC) mickael.adam@all4tec.net - bug 512343
 *****************************************************************************/

package org.eclipse.papyrus.infra.gmfdiag.common.service.palette;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
import org.eclipse.ui.IMemento;

/**
 * Class that defines a profile for a palette.
 * @since 3.0
 */
public class PapyrusPaletteDescription implements IPaletteDescription {

	/** name of the palette */
	private String name;

	/** id of the editor to contribute */
	private String contributionEditorID;

	/** contribution of this palette */
	private Object contributions;

	/** id of the palette */
	private String paletteID;

	/** priority of the palette */
	private ProviderPriority priority;

	/** properties of the palette */
	private Map<String, String> properties;

	/**
	 * Creates a new PapyrusPaletteDescription.
	 */
	public PapyrusPaletteDescription() {
	}

	/**
	 * Create a new Palette description using a preference memento
	 *
	 * @param memento
	 *            the memento from which to read the description
	 * @return the content of the palette
	 */
	public static IPaletteDescription create(IMemento memento) {
		final PapyrusPaletteDescription description = new PapyrusPaletteDescription();
		description.setName(memento.getString(IPapyrusPaletteConstant.NAME));
		description.setPaletteID(memento.getString(IPapyrusPaletteConstant.ID));
		description.setContributionEditorID(memento.getString(IPapyrusPaletteConstant.EDITOR_ID));
		description.setContributions(memento.getString(IPapyrusPaletteConstant.PATH));
		description.setPriority(ProviderPriority.parse(memento.getString(IPapyrusPaletteConstant.PRIORITY)));

		// retrieve the map of properties
		IMemento propertiesMemento = memento.getChild(IPapyrusPaletteConstant.PALETTE_DESCRIPTION_PROPERTIES);
		Map<String, String> properties = new HashMap<String, String>();
		if (propertiesMemento != null) {
			// retrieve the child name/value tuple for each children
			for (String key : propertiesMemento.getAttributeKeys()) {
				properties.put(key, propertiesMemento.getString(key));
			}
		}
		description.setProperties(properties);
		// contributions: do not read the file before it is necessary...
		return description;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getContributionEditorID() {
		return contributionEditorID;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object getContributions() {
		return contributions;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getName() {
		return name;
	}

	/**
	 * Sets the name of the palette description
	 *
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the id of the editor to contribute
	 *
	 * @param contributionEditorID
	 *            the contributionEditorID to set
	 */
	public void setContributionEditorID(String contributionEditorID) {
		this.contributionEditorID = contributionEditorID;
	}

	/**
	 * Sets the contributions of this palette
	 *
	 * @param contributions
	 *            the contributions to set
	 */
	public void setContributions(Object contributions) {
		this.contributions = contributions;
	}

	/**
	 * Sets the id of this palette
	 *
	 * @param paletteID
	 *            the paletteID to set
	 */
	public void setPaletteID(String paletteID) {
		this.paletteID = paletteID;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getPaletteID() {
		return paletteID;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ProviderPriority getPriority() {
		return priority;
	}

	/**
	 * Sets the priority for this palette
	 *
	 * @param priority
	 *            the priority to set
	 */
	public void setPriority(ProviderPriority priority) {
		this.priority = priority;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Map<String, String> getProperties() {
		return properties;
	}

	/**
	 * Sets the properties for this palette description
	 *
	 * @param properties
	 *            the properties to set
	 */
	public void setProperties(Map<String, String> properties) {
		this.properties = properties;
	}

}

Back to the top