Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 97d59b906382bc3b4083b407b66113716a762db1 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*****************************************************************************
 * Copyright (c) 2016 CEA LIST and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
 *****************************************************************************/
package org.eclipse.papyrus.toolsmiths.palette.provider;

import java.util.Collection;

import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.PaletteUtil;

/**
 * Content provider for available tools viewer
 */
public class UMLToolsTreeContentProvider implements ITreeContentProvider {

	/**
	 * Constructor
	 *
	 * @param viewer
	 *            The viewer whose ContentProvider this content provider is
	 */
	public UMLToolsTreeContentProvider() {
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void dispose() {
		// Do nothing
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object[] getChildren(final Object parentElement) {
		Object[] elements = null;

		if (parentElement instanceof Collection<?>) {
			elements = ((Collection<?>) parentElement).toArray();
		} else if (parentElement instanceof PaletteRoot) {
			// paletteUil.getAllEntries(...) to add drawers
			// if so, uncomment the addFilterbutton for drawers in populate tool bar
			elements = PaletteUtil.getAllToolEntries(((PaletteRoot) parentElement)).toArray();
		}

		return elements;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object[] getElements(final Object inputElement) {
		Object[] elements = null;

		if (inputElement instanceof Collection<?>) {
			elements = ((Collection<?>) inputElement).toArray();
		} else if (inputElement instanceof PaletteRoot) {
			// paletteUil.getAllEntries(...) to add drawers
			// if so, uncomment the addFilterbutton for drawers in populate tool bar
			elements = PaletteUtil.getAllToolEntries(((PaletteRoot) inputElement)).toArray();
		}

		if (elements == null) {
			elements = new Object[0];
		}
		return elements;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object getParent(final Object element) {
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean hasChildren(final Object element) {
		return null != getChildren(element) && 0 < getChildren(element).length;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
		// Do nothing
	}
}

Back to the top