Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f19a2852d2f1e35059e71df118fa6bc3736b42bf (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
/*****************************************************************************
 * Copyright (c) 2009 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.customization.palette.dialog;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPaletteAspectToolEntryProxy;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypePostAction;
import org.eclipse.swt.graphics.Image;
import org.w3c.dom.NodeList;

/**
 * Proxy for the aspect tool entries
 */
public class PaletteAspectToolEntryProxy extends PaletteEntryProxy implements IPaletteAspectToolEntryProxy {

	/** list of post actions executed by the tool */
	protected List<IPostAction> postActions = new ArrayList<IPostAction>();

	/** list of pre actions executed by the tool */
	protected List<IPreAction> preActions = new ArrayList<IPreAction>();

	/**
	 * Creates a new {@link PaletteAspectToolEntryProxy}
	 * 
	 * @param entry
	 *        the proxied entry
	 */
	public PaletteAspectToolEntryProxy(AspectCreationEntry entry) {
		super(entry);

		initAspectActions();
	}

	/**
	 * returns the list of post actions attached to this {@link PaletteAspectToolEntryProxy}
	 * 
	 * @return the list of post actions attached to this {@link PaletteAspectToolEntryProxy}
	 */
	public List<IPostAction> getPostActions() {
		return postActions;
	}

	/**
	 * Sets the list of post actions attached to this {@link PaletteAspectToolEntryProxy}
	 * <p>
	 * Warning! This should not be used to initialize the list of action, only move the already existing actions.
	 * </p>
	 * 
	 * @param postActions
	 *        the postActions to set
	 */
	public void setPostActions(List<IPostAction> postActions) {
		this.postActions = postActions;
	}

	/**
	 * returns the list of pre actions attached to this {@link PaletteAspectToolEntryProxy}
	 * 
	 * @return the list of pre actions attached to this {@link PaletteAspectToolEntryProxy}
	 */
	public List<IPreAction> getPreActions() {
		return preActions;
	}

	/**
	 * Sets the list of pre actions attached to this {@link PaletteAspectToolEntryProxy}
	 * <p>
	 * Warning! This should not be used to initialize the list of action, only move the already existing actions.
	 * 
	 * @param preActions
	 *        the preActions to set
	 */
	protected void setPreActions(List<IPreAction> preActions) {
		this.preActions = preActions;
	}

	/**
	 * returns the list of aspect actions attached to this {@link PaletteAspectToolEntryProxy}
	 * 
	 * @return the list of aspect actions attached to this {@link PaletteAspectToolEntryProxy}
	 */
	public List<IAspectAction> getAspectActions() {
		List<IAspectAction> actions = new ArrayList<IAspectAction>();
		actions.addAll(preActions);
		actions.addAll(postActions);
		return actions;
	}

	/**
	 * Initializes the aspect actions
	 */
	protected void initAspectActions() {
		Object value = getEntry().getAspectProperties(IPapyrusPaletteConstant.ASPECT_ACTION_KEY);
		if(value instanceof NodeList) {
			PaletteUtil.initAspectActions((NodeList)value, postActions, preActions);
		}
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	public String getDescription() {
		return getEntry().getDescription();
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	public String getImagePath() {
		String path = getEntry().getIconPath();
		return (path != null) ? path : "";
	}

	/**
	 * returns the small icon of the cached entry
	 * 
	 * @return the small icon of the cached entry
	 */
	@Override
	public Image getImage() {
		if(getImagePath() != null && !getImagePath().equals("")) {
			return Activator.getPluginIconImage(Activator.ID, getImagePath());
		}
		return super.getImage();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public AspectCreationEntry getEntry() {
		return (AspectCreationEntry)super.getEntry();
	}

	/**
	 * Returns the ID of the referenced entry of the aspect entry
	 * 
	 * @return the ID of the referenced entry of the aspect entry
	 */
	public String getReferencedPaletteID() {
		return getEntry().getReferencedEntry().getId();
	}

	/**
	 * Returns the list of stereotypes Qualified names to apply
	 * 
	 * @return the list of stereotypes qualified names to apply
	 */
	public List<String> getStereotypesQNList() {
		List<String> list = new ArrayList<String>();
		for(IAspectAction action : postActions) {
			if(action instanceof StereotypePostAction) {
				list.addAll(((StereotypePostAction)action).getStereotypesToApply());
			}
		}
		return list;
	}

}

Back to the top