Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 02918d8e8fe1944a442e8b93960db81f13c4372a (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
/*******************************************************************************
 * Copyright (c) 2015 protos software gmbh (http://www.protos.de).
 * 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:
 * 		Juergen Haug (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.ui.common.base.support;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.doc.ContextHelpProvider;
import org.eclipse.etrice.ui.common.base.BaseImageProvider;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;

public class HelpFeature extends AbstractCustomFeature {

	public HelpFeature(IFeatureProvider fp) {
		super(fp);
	}

	protected String getBoClassName(PictogramElement pe) {
		Object bo = getBusinessObjectForPictogramElement(pe);
		if (bo instanceof EObject)
			return ((EObject) bo).eClass().getName();

		return null;
	}

	public String getFeatureId(ICustomContext context) {
		if (context instanceof ICustomContext) {
			ICustomContext peContext = (ICustomContext) context;
			if (peContext.getPictogramElements() != null && peContext.getPictogramElements().length == 1){
				PictogramElement pe = peContext.getPictogramElements()[0];
				// don't show help for diagram input
				if(getBusinessObjectForPictogramElement(pe) == getBusinessObjectForPictogramElement(getDiagram()))
					return null;
				return getBoClassName(pe);
			}
		}

		return null;
	}

	@Override
	public boolean canExecute(ICustomContext context) {
		String featureId = getFeatureId(context);
		if (featureId != null)
			return ContextHelpProvider.isAvailable(featureId);

		return false;
	}

	@Override
	public void execute(ICustomContext context) {
		ContextHelpProvider.showHelp(getBoClassName(((ICustomContext) context).getPictogramElements()[0]));
	}

	@Override
	public String getName() {
		return "Help";
	}

	@Override
	public String getDescription() {
		return "Open help view";
	}

	@Override
	public String getImageId() {
		return BaseImageProvider.IMG_HELP;
	}

	@Override
	public boolean hasDoneChanges() {
		return false;
	}

}

Back to the top