summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/ProjectSpecificContributionItem.java
blob: 7ba7df1cc983de1dc221fe35347cf3fbb02293bd (plain)
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
/*******************************************************************************
 * Copyright (c) 2013 BMW Car IT GmbH.
 * 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:
 * BMW Car IT - initial implementation
 *******************************************************************************/

package org.yocto.sdk.ide;

import java.util.ArrayList;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.services.IServiceLocator;
import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults;
import org.yocto.sdk.ide.actions.ProfileSwitchHandler;
import org.yocto.sdk.ide.utils.ProjectPreferenceUtils;

public class ProjectSpecificContributionItem extends TargetProfileContributionItem {
	private static final String PROJECT_SPECIFIC_PROFILE =
			"Preferences.Profile.ProjectSpecific.Profile.Label"; //$NON-NLS-N$
	private static final String DISABLED_COMMAND_ID = "org.yocto.sdk.ide.command.disabled"; //$NON-NLS-N$

	private IServiceLocator serviceLocator;

	public ProjectSpecificContributionItem() {}

	public ProjectSpecificContributionItem(String id) {
		super(id);
	}

	@Override
	protected IContributionItem[] getContributionItems() {
		ArrayList<IContributionItem> items = new ArrayList<IContributionItem>();

		IProject project = getSelectedProject(serviceLocator);
		if (project != null) {
			YoctoUIElement yoctoUIElement = ProjectPreferenceUtils.getElem(project);
			SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(yoctoUIElement);

			if ((result != SDKCheckResults.SDK_PASS)) {
				CommandContributionItemParameter parameter = new CommandContributionItemParameter(serviceLocator,
																								null,
																								DISABLED_COMMAND_ID,
																								CommandContributionItem.STYLE_PUSH);

				parameter.label = YoctoSDKMessages.getString(PROJECT_SPECIFIC_PROFILE);

				items.add(new CommandContributionItem(parameter));
			} else {
				items.add(super.createProfileItem(serviceLocator, ProfileSwitchHandler.PROJECT_SPECIFIC_PARAMETER,
												YoctoSDKMessages.getString(PROJECT_SPECIFIC_PROFILE)));
			}

			updateSelection(serviceLocator);
		}

		return items.toArray(new IContributionItem[items.size()]);
	}

	@Override
	public void initialize(IServiceLocator serviceLocator) {
		this.serviceLocator = serviceLocator;
	}
}