Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009 Mykola Nikishov <mn@mn.com.ua> |
3 |
* |
4 |
* All rights reserved. This program and the accompanying materials |
5 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* which accompanies this distribution, and is available at |
7 |
* http://www.eclipse.org/legal/epl-v10.html |
8 |
******************************************************************************/ |
9 |
|
10 |
package org.eclipse.ui.internal.handlers; |
11 |
|
12 |
import org.eclipse.core.commands.AbstractHandler; |
13 |
import org.eclipse.core.commands.ExecutionEvent; |
14 |
import org.eclipse.core.commands.ExecutionException; |
15 |
import org.eclipse.core.resources.IProject; |
16 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.IAdaptable; |
18 |
import org.eclipse.ui.IWorkingSet; |
19 |
import org.eclipse.ui.PlatformUI; |
20 |
|
21 |
public abstract class WorkingSetHandler extends AbstractHandler { |
22 |
|
23 |
protected abstract boolean isAplicable(IProject project); |
24 |
|
25 |
protected abstract void executeOperation(IProject project) |
26 |
throws CoreException; |
27 |
|
28 |
public final Object execute(ExecutionEvent event) throws ExecutionException { |
29 |
String parameter = event.getParameter(getParameterId()); |
30 |
IWorkingSet workingSetToClose = PlatformUI.getWorkbench() |
31 |
.getWorkingSetManager().getWorkingSet(parameter); |
32 |
IAdaptable[] elements = workingSetToClose.getElements(); |
33 |
for (int j = 0; j < elements.length; j++) { |
34 |
IProject project = (IProject) elements[j] |
35 |
.getAdapter(IProject.class); |
36 |
if (project != null && isAplicable(project)) { |
37 |
try { |
38 |
executeOperation(project); |
39 |
} catch (CoreException e) { |
40 |
// TODO Auto-generated catch block |
41 |
e.printStackTrace(); |
42 |
} |
43 |
} |
44 |
} |
45 |
return null; |
46 |
} |
47 |
|
48 |
protected abstract String getParameterId(); |
49 |
|
50 |
} |