Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 29a9a91a8fa17bb243860b1c1ffdf580588989a6 (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
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.launch.ui.internal.adapters;

import org.eclipse.core.runtime.Assert;
import org.eclipse.tcf.te.launch.ui.model.LaunchModel;
import org.eclipse.tcf.te.launch.ui.model.LaunchNode;
import org.eclipse.tcf.te.ui.views.Managers;
import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable;

/**
 * Categorizable launch config node adapter implementation
 */
public class CategorizableAdapter implements ICategorizable {
	// Reference to the adapted element
	private final LaunchNode node;

	/**
	 * Constructor.
	 *
	 * @param node The adapted launch config node. Must not be <code>null</code>.
	 */
	public CategorizableAdapter(LaunchNode node) {
		Assert.isNotNull(node);
		this.node = node;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#getId()
	 */
	@Override
	public String getId() {
		return LaunchModel.getCategoryId(node.getLaunchConfiguration());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#isValid(org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable.OPERATION, org.eclipse.tcf.te.ui.views.interfaces.ICategory, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
	 */
	@Override
	public boolean isValid(OPERATION operation, ICategory parentCategory, ICategory category) {
		Assert.isNotNull(operation);
		Assert.isNotNull(category);

		if (OPERATION.REMOVE.equals(operation) && parentCategory != null && IUIConstants.ID_CAT_FAVORITES.equals(parentCategory.getId())) {
			return true;
		}
		if (OPERATION.ADD.equals(operation) && IUIConstants.ID_CAT_FAVORITES.equals(category.getId())) {
			return true;
		}

		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#isEnabled(org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable.OPERATION, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
	 */
	@Override
	public boolean isEnabled(OPERATION operation, ICategory category) {
		Assert.isNotNull(operation);
		Assert.isNotNull(category);

		if (OPERATION.REMOVE.equals(operation)) {
			return Managers.getCategoryManager().belongsTo(IUIConstants.ID_CAT_FAVORITES, getId());
		}
		if (OPERATION.ADD.equals(operation)) {
			return !Managers.getCategoryManager().belongsTo(IUIConstants.ID_CAT_FAVORITES, getId());
		}
		return false;
	}
}

Back to the top