Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0d8d6cc21c4cb10b40afe0c4e7a7486efb5d066f (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
/*******************************************************************************
 * All rights reserved. This program and the accompanying materials
 * are property of the CEA, their use is subject to specific agreement 
 * with the CEA.
 * 
 * Contributors:
 *    CEA LIST - initial API and implementation
 *******************************************************************************/

package org.eclipse.papyrus.qompass.designer.core.handlers;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.papyrus.FCM.InteractionComponent;
import org.eclipse.papyrus.qompass.designer.core.CommandSupport;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.papyrus.qompass.designer.core.dialogs.ConnectorSelectionDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Feature;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.util.UMLUtil;

/**
 * Implementation class for ClassAction action
 */
public class SelectConnectorHandler extends CmdHandler {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isEnabled() {
		updateSelectedEObject();
		EObject selectedObj = getSelectedEObject();
		if((selectedObj instanceof Connector) || (selectedObj instanceof Property)) {
			return true;
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {
		// feature is a common superclass of Connector and Property
		if(!(getSelectedEObject() instanceof Feature)) {
			return null;
		}
		// get selected connector
		final Feature selectedConnector = (Feature)getSelectedEObject();
		Shell shell = new Shell();

		// 1. select possible connectors according to port types
		// (only show compatible connectors check-box?)
		// 2. select implementation group according to connector type

		Model model = selectedConnector.getModel();

		ConnectorSelectionDialog elementSelector =
			new ConnectorSelectionDialog(shell, model, selectedConnector);
		elementSelector.setTitle("Select connector");
		elementSelector.setMessage("Select an implementation for connector " + selectedConnector.getName());
		elementSelector.open();
		if(elementSelector.getReturnCode() == IDialogConstants.OK_ID) {
			final Object[] result = elementSelector.getResult();
			if((result.length == 1) && (result[0] instanceof Class)) {
				CommandSupport.exec("Select connector", event, new Runnable() {

					public void run() {
						org.eclipse.papyrus.FCM.Connector fcmSelectedConnector = StereotypeUtil.applyApp(selectedConnector, org.eclipse.papyrus.FCM.Connector.class);
						InteractionComponent newConnType = UMLUtil.getStereotypeApplication((Class)result[0], InteractionComponent.class);
						fcmSelectedConnector.setIc(newConnType);
					}
				});
			}
		}
		return null;
	}
}

Back to the top