Skip to main content
summaryrefslogtreecommitdiffstats
blob: 652d75ac583dba9f1f1199359c68103cd8428ded (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
/*******************************************************************************
* Copyright (c) 2010 Oracle. 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:
*     Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.actions;

import java.util.Iterator;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;

/**
 *  GenerateEntitiesAction
 */
public abstract class ObjectAction extends ActionDelegate implements IObjectActionDelegate 
{
	private ISelection currentSelection;

	public ObjectAction() {
		super();
	}

	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// do nothing
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
        this.currentSelection = selection;
	}

	@Override
	public void run(IAction action) {
		if (this.currentSelection instanceof ITreeSelection) {
			for (Iterator<?> stream = ((ITreeSelection) this.currentSelection).iterator(); stream.hasNext(); ) {
				this.execute(stream.next());
			}
		}
	}

	protected void execute(Object selection) {
		
		if(selection instanceof IFile) {
			this.execute((IFile)selection);
		}
	}

	@SuppressWarnings("unused")
	protected void execute(IFile file) {
		throw new UnsupportedOperationException();
	}

}

Back to the top