Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9c343fb0e93a12d3d49f872881fdeb8bbc3f62d3 (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
/*****************************************************************************
 * 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.uml.diagram.clazz.custom.ui;

import java.util.HashSet;

import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Association;

/**
 * This class can be launch is order to open a dialog used to choose an association
 */
public class AssociationSelectionDialog extends AbstractAssociationSelectionDialog {

	/** The selected association. */
	protected Association selectedAssociation;

	/** The common associations. */
	protected HashSet<Association> commonAssociations;

	/**
	 * Instantiates a new association selection dialog.
	 *
	 * @param parent
	 *            the parent shell
	 * @param style
	 *            the style
	 * @param commonAssociations
	 *            list of assocation in which we would like to llok for
	 */
	public AssociationSelectionDialog(Shell parent, int style, HashSet<Association> commonAssociations) {
		super(parent, style);
		this.commonAssociations = commonAssociations;
		this.selectedAssociation = (Association) commonAssociations.toArray()[0];
	}

	/**
	 * @see org.eclipse.papyrus.uml.diagram.clazz.custom.ui.AbstractAssociationSelectionDialog#createContents()
	 *
	 */
	@Override
	protected void createContents() {
		// TODO Auto-generated method stub
		super.createContents();
		final ILabelProvider labelProvider = new AdapterFactoryLabelProvider(org.eclipse.papyrus.uml.diagram.clazz.part.UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
		final IStructuredContentProvider associationContentProvider = new IStructuredContentProvider() {

			@Override
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			}

			@Override
			public void dispose() {
			}

			@Override
			public Object[] getElements(Object inputElement) {
				return commonAssociations.toArray();
			}
		};
		final TableViewer tableViewer = new TableViewer(table);
		tableViewer.setLabelProvider(labelProvider);
		tableViewer.setContentProvider(associationContentProvider);
		tableViewer.setInput(commonAssociations);
		btnOk.addMouseListener(new MouseListener() {

			@Override
			public void mouseUp(MouseEvent e) {
				ISelection selection = tableViewer.getSelection();
				if (selection instanceof IStructuredSelection) {
					selectedAssociation = (Association) ((IStructuredSelection) selection).getFirstElement();
					shlAssociationselection.close();
				}
			}

			@Override
			public void mouseDown(MouseEvent e) {
			}

			@Override
			public void mouseDoubleClick(MouseEvent e) {
			}
		});
		btnCancel.setVisible(false);
	}

	/**
	 * Gets the selected association.
	 *
	 * @return the selected association
	 */
	public Association getSelectedAssociation() {
		return selectedAssociation;
	}
}

Back to the top