Skip to main content
summaryrefslogtreecommitdiffstats
blob: bdc6904db3559722038b87d5a0ea006d0966a0e4 (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
/*
 * generated by Xtext
 */
package org.eclipse.papyrus.uml.textedit.transition.xtext.ui.contentassist;

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

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.papyrus.uml.textedit.transition.xtext.scoping.UmlTransitionScopeProvider;
import org.eclipse.papyrus.uml.textedit.transition.xtext.umlTransition.CallOrSignalEventRule;
import org.eclipse.papyrus.uml.textedit.transition.xtext.umlTransition.EventRule;
import org.eclipse.papyrus.uml.textedit.transition.xtext.umlTransition.TransitionRule;
import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementUtil;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;

/**
 * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
 */
public class UmlTransitionProposalProvider extends AbstractUmlTransitionProposalProvider {

	@Override
	public void complete_CallOrSignalEventRule(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// TODO Auto-generated method stub
		TransitionRule rule = (TransitionRule) model;
		List<EObject> operationAndSignals = UmlTransitionScopeProvider.getVisibleOperationAndSignals(ContextElementUtil.getContextElement(model.eResource()));
		List<EObject> alreadyUsedOperationAndSignals = new ArrayList<EObject>();
		if (rule != null && rule.getTriggers() != null && !rule.getTriggers().isEmpty()) {
			List<EventRule> eventRules = rule.getTriggers();
			for (EventRule eventRule : eventRules) {
				if (eventRule instanceof CallOrSignalEventRule) {
					CallOrSignalEventRule callOrSignalEventRule = (CallOrSignalEventRule) eventRule;
					if (callOrSignalEventRule.getOperationOrSignal() != null) {
						alreadyUsedOperationAndSignals.add(callOrSignalEventRule.getOperationOrSignal());
					}
				}
			}
		}
		operationAndSignals.removeAll(alreadyUsedOperationAndSignals);
		for (EObject o : operationAndSignals) {
			NamedElement opOrSignal = (NamedElement) o;
			if (opOrSignal.getName().startsWith(context.getPrefix())) {
				String completionString = opOrSignal.getName().substring(context.getPrefix().length());
				ICompletionProposal completionProposal = new CompletionProposal(completionString, // String to be inserted
						context.getOffset(), // Offset
						context.getSelectedText().length(), // Replacement length
						completionString.length(), // cursorPosition
						null, // image
						opOrSignal.getName() + " - " + (opOrSignal instanceof Operation ? "Operation" : "Signal"), // displayString
						null, // contextInformation
						(opOrSignal instanceof Operation ? "Operation associated with the CallEvent of this trigger" : "Signal associated with the SignalEvent of this trigger") // additionalProposalInfo
				);
				// acceptor.accept(new CompletionProposal(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo))
				acceptor.accept(completionProposal);
			}
		}
	}



}

Back to the top