Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2a15b7a081077df0bf843438e12e51a50afc30fb (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
190
191
192
193
194
195
196
/*****************************************************************************
 * 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:
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
 */
package org.eclipse.papyrus.diagram.clazz.custom.ui;

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

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.diagram.common.ui.dialogs.ElementChooseDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.ParameterableElement;
import org.eclipse.uml2.uml.TemplateSignature;

// TODO: Auto-generated Javadoc
/**
 * this class is used to select parameterable element by taking account the kind of the paramter.
 */
public class TemplateParameterConfigurationDialog extends AbstractTemplateParameterConfigurationDialog {

	/** The templatesignature. */
	protected TemplateSignature templatesignature;

	/** The parameterable element. */
	protected ParameterableElement parameterableElement;

	/** The defaultparameterable element. */
	protected ParameterableElement defaultparameterableElement;

	/** The eclass. */
	protected EClass eclass;

	/** The not wanted. */
	protected List<EClass> notWanted = null;


	/**
	 * Gets the parameterable element.
	 * 
	 * @return the parameterable element
	 */
	public ParameterableElement getParameterableElement() {
		return parameterableElement;
	}


	/**
	 * Gets the defaultparameterable element.
	 * 
	 * @return the defaultparameterable element
	 */
	public ParameterableElement getDefaultparameterableElement() {
		return defaultparameterableElement;
	}

	/**
	 * Instantiates a new template parameter configuration dialog.
	 * 
	 * @param parent
	 *        the shell parent
	 * @param style
	 *        the style see {@link SWT}
	 * @param elementtype
	 *        the elementtype the kind of parameterable element that we look for
	 */
	public TemplateParameterConfigurationDialog(Shell parent, int style, EClass elementtype) {
		super(parent, style);
		this.eclass = elementtype;
		this.notWanted = new ArrayList<EClass>();
	}

	/**
	 * Instantiates a new template parameter configuration dialog.
	 * 
	 * @param parent
	 *        the parent
	 * @param style
	 *        the style
	 * @param elementtype
	 *        the elementtype
	 * @param eclassNotWanted
	 *        the list of eclass that we do not want to select, can not be null
	 */
	public TemplateParameterConfigurationDialog(Shell parent, int style, EClass elementtype, List<EClass> eclassNotWanted) {
		super(parent, style);
		this.eclass = elementtype;
		assert (notWanted != null);
		this.notWanted = eclassNotWanted;
	}

	/**
	 * Sets the owner.
	 * 
	 * @param templateSignature
	 *        the new owner
	 */
	public void setOwner(TemplateSignature templateSignature) {
		this.templatesignature = templateSignature;
	}

	/**
	 * @see org.eclipse.papyrus.diagram.clazz.custom.ui.AbstractTemplateParameterConfigurationDialog#createContents()
	 * 
	 */

	@Override
	protected void createContents() {
		// TODO Auto-generated method stub
		super.createContents();
		getParameteredElementContent().setText("");
		getDefaultElementContent().setText("");
		final ILabelProvider labelProvider = new AdapterFactoryLabelProvider(org.eclipse.papyrus.diagram.clazz.part.UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
		getChoosePararameteredElementButton().addMouseListener(new MouseListener() {

			public void mouseUp(MouseEvent e) {

				ElementChooseDialog elementChoose = new ElementChooseDialog(new Shell(), SWT.None, templatesignature.getTemplate(), eclass, notWanted);
				if(elementChoose.open() != null) {
					parameterableElement = ((ParameterableElement)elementChoose.getSelectedElement());
					labelProvider.getText(parameterableElement);
					getParameteredElementContent().setText(labelProvider.getText(parameterableElement));
					getParameteredElementContent().setImage(labelProvider.getImage(parameterableElement));
				}


			}

			public void mouseDown(MouseEvent e) {
			}

			public void mouseDoubleClick(MouseEvent e) {
			}
		});
		getChooseDefaultParameterButton().addMouseListener(new MouseListener() {


			public void mouseUp(MouseEvent e) {
				if(parameterableElement != null) {
					ElementChooseDialog elementChoose = new ElementChooseDialog(new Shell(), SWT.None, templatesignature.getTemplate(), parameterableElement.eClass());
					if(elementChoose.open() != null) {
						defaultparameterableElement = ((ParameterableElement)elementChoose.getSelectedElement());
						labelProvider.getText(defaultparameterableElement);
						getDefaultElementContent().setText(labelProvider.getText(defaultparameterableElement));
						getDefaultElementContent().setImage(labelProvider.getImage(defaultparameterableElement));
					}
				}
			}

			public void mouseDown(MouseEvent e) {
			}

			public void mouseDoubleClick(MouseEvent e) {
			}
		});
		getBtnCancel().addMouseListener(new MouseListener() {

			public void mouseUp(MouseEvent e) {
				getParent().close();
				defaultparameterableElement = null;
				parameterableElement = null;
			}

			public void mouseDown(MouseEvent e) {
			}

			public void mouseDoubleClick(MouseEvent e) {
			}
		});
		getBtnExecute().addMouseListener(new MouseListener() {

			public void mouseUp(MouseEvent e) {
				getParent().close();
			}

			public void mouseDown(MouseEvent e) {
			}

			public void mouseDoubleClick(MouseEvent e) {
			}
		});
	}
}

Back to the top