Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c2b82a989d6b3f8aaa1fe36fdc19759bcaff66f0 (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
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST.
 * 
 * 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:
 *   CEA LIST - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.views.validation.internal.actions;

import java.util.Collection;
import java.util.Collections;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.actions.BaseSelectionListenerAction;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

/**
 * This is the AbstractMarkerAction type. Enjoy.
 */
public class AbstractMarkerAction
		extends BaseSelectionListenerAction {

	private IWorkbenchSite site;

	private Collection<IPapyrusMarker> markers;

	public AbstractMarkerAction(IWorkbenchSite site, String label) {
		super(label);

		this.site = site;
		
		setEnabled(false);
	}

	protected IWorkbenchSite getSite() {
		return site;
	}

	protected IPapyrusMarker getMarker() {
		return Iterables.getFirst(markers, null);
	}

	protected Collection<IPapyrusMarker> getMarkers() {
		return markers;
	}

	@Override
	protected boolean updateSelection(IStructuredSelection selection) {
		markers = selection.isEmpty()
			? Collections.<IPapyrusMarker> emptyList()
			: Lists.newArrayList(Iterables.filter(selection.toList(),
				IPapyrusMarker.class));

		return !markers.isEmpty() && super.updateSelection(selection);
	}
}

Back to the top