Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c158568096c77a0400dcc1be8791b56555f4e7a4 (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
/*****************************************************************************
 * Copyright (c) 2009, 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 - Move from oep.uml.diagram.com and remove aspect actions framework, see bug 512343.
 *
 *****************************************************************************/

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

import java.util.List;
import java.util.Map;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;

/**
 * Entry that uses the functionality of another entry.
 */
public class AspectCreationEntry extends CombinedTemplateCreationEntry implements Cloneable {

	/** overriden palette entry */
	protected CombinedTemplateCreationEntry entry;

	/** Tool object for this entry */
	protected Tool tool;

	/** properties for the tool */
	protected Map<?, ?> properties;

	/** specific icon path */
	private String iconPath;

	/** saves the image descriptor used by this entry */
	private ImageDescriptor descriptor;

	private final static String URL_IMAGE_DESCRIPTOR_BEGIN = "URLImageDescriptor(";

	/**
	 * Creates a new AspectCreationEntry
	 *
	 * @param name
	 * @param desc
	 * @param id
	 * @param descriptor
	 * @param entry
	 * @param properties
	 */
	public AspectCreationEntry(String name, String desc, String id, ImageDescriptor descriptor, CombinedTemplateCreationEntry entry, Map<?, ?> properties) {
		super(name, desc, null, descriptor, descriptor);
		setId(id);
		// computes the icon path
		// due to visibility problems on URL image descriptor, use the
		// toString() method...
		computeIconPathFromImageDescriptor(descriptor);
		this.entry = entry;
		this.properties = properties;
		this.descriptor = descriptor;
	}

	/**
	 * Computes the icon path for the URL image descriptor
	 */
	protected void computeIconPathFromImageDescriptor(ImageDescriptor desc) {
		String value = desc.toString();
		if (value.startsWith("URLImageDescriptor(")) {
			String url = value.substring(URL_IMAGE_DESCRIPTOR_BEGIN.length(), value.length() - 1);
			setIconPath(url);
		}
	}

	/**
	 * Creates a new AspectCreationEntry
	 *
	 * @param name
	 * @param desc
	 * @param id
	 * @param iconPath
	 * @param entry
	 * @param properties
	 */
	public AspectCreationEntry(String name, String desc, String id, String iconPath, CombinedTemplateCreationEntry entry, Map<?, ?> properties) {
		super(name, desc, null, Activator.getImageDescriptor(iconPath), Activator.getImageDescriptor(iconPath));
		setId(id);
		this.setIconPath(iconPath);
		this.entry = entry;
		this.properties = properties;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Tool createTool() {
		if (tool == null) {
			if (entry instanceof AspectCreationEntry) {
				// clone to avoid reuse of the same tool than other aspect creation entries (see bug 412735)
				AspectCreationEntry clonedEntry = ((AspectCreationEntry) entry).clone();
				tool = clonedEntry.createTool();
			} else {
				tool = entry.createTool();
			}
			tool.setProperties(properties);
		}
		return tool;
	}

	/**
	 * Returns the specific properties for aspect actions
	 *
	 * @param key
	 *            the key of the properties
	 * @return the specific properties for aspect actions
	 */
	public Object getAspectProperties(String key) {
		return properties.get(key);
	}

	/**
	 * Returns the referenced entry
	 *
	 * @return the referenced entry
	 */
	public CombinedTemplateCreationEntry getReferencedEntry() {
		return entry;
	}

	/**
	 * Returns the list of stereotypes to apply post creation
	 *
	 * @return the list of stereotypes to apply post creation
	 */
	@SuppressWarnings("unchecked")
	public List<String> getStereotypeList() {
		return (List<String>) properties.get(IPapyrusPaletteConstant.STEREOTYPES_TO_APPLY_KEY);
	}

	/**
	 * @param path
	 *            the iconPath to set
	 */
	public void setIconPath(String path) {
		iconPath = path;
	}

	/**
	 * @return the iconPath
	 */
	public String getIconPath() {
		return iconPath;
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	public AspectCreationEntry clone() {
		if (getIconPath() != null) {
			return new AspectCreationEntry(this.getLabel(), this.getDescription(), entry.getId() + "_" + System.currentTimeMillis(), this.getIconPath(), this.entry, this.properties);
		}
		return new AspectCreationEntry(this.getLabel(), this.getDescription(), entry.getId() + "_" + System.currentTimeMillis(), this.descriptor, this.entry, this.properties);
	}
}

Back to the top