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
| package net.developpez.workspaceplugin.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISources;
public class CreateDeployerProjectHandler extends AbstractHandler {
public CreateDeployerProjectHandler() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Object appContextObj = event.getApplicationContext();
if (appContextObj instanceof IEvaluationContext) {
IEvaluationContext appContext = (IEvaluationContext) appContextObj;
ISelection selection = (ISelection) appContext
.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
// les tests sont redondants par rapport aux extensions (cela n'est pas nécessaire, mais plus sûr au cas où on se trompe les enabledWhen, visibleWhen...)
if ( selection instanceof IStructuredSelection ) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if ( structuredSelection.size()==1 ) {
Object element = structuredSelection.getFirstElement();
if ( element instanceof ICompilationUnit ) {
execute((ICompilationUnit)element);
}
}
}
}
return null;
}
private void execute(ICompilationUnit file) {
MessageDialog.openInformation(null,
"Fichier sélectionné",
String.format("Path: %s%n", file.getPath()
)
);
}
} |
Partager