use of org.eclipse.core.expressions.EvaluationContext in project che by eclipse.
the class ParticipantExtensionPoint method createEvaluationContext.
//---- Helper methods ------------------------------------------------------------------
private static EvaluationContext createEvaluationContext(RefactoringProcessor processor, Object element, String[] affectedNatures) {
EvaluationContext result = new EvaluationContext(null, element);
result.setAllowPluginActivation(true);
//$NON-NLS-1$
result.addVariable("element", element);
//$NON-NLS-1$
result.addVariable("affectedNatures", Arrays.asList(affectedNatures));
//$NON-NLS-1$
result.addVariable("processorIdentifier", processor.getIdentifier());
return result;
}
use of org.eclipse.core.expressions.EvaluationContext in project che by eclipse.
the class ParticipantExtensionPoint method getParticipants.
/**
* Returns all participants for a given element.
*
* @param status a refactoring status to report status if problems occurred while
* loading the participants
* @param processor the processor that will own the participants
* @param element the element to be copied or a corresponding descriptor
* @param arguments the arguments for the participants
* @param filter a participant filter to exclude certain participants, or <code>null</code>
* if no filtering is desired
* @param affectedNatures an array of project natures affected by the refactoring
* @param shared a list of shared participants
*
* @return an array of participants
*/
public RefactoringParticipant[] getParticipants(RefactoringStatus status, RefactoringProcessor processor, Object element, RefactoringArguments arguments, IParticipantDescriptorFilter filter, String[] affectedNatures, SharableParticipants shared) {
if (fParticipants == null)
init();
EvaluationContext evalContext = createEvaluationContext(processor, element, affectedNatures);
List result = new ArrayList();
for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
ParticipantDescriptor descriptor = (ParticipantDescriptor) iter.next();
if (!descriptor.isEnabled()) {
iter.remove();
} else {
try {
RefactoringStatus filterStatus = new RefactoringStatus();
if (descriptor.matches(evalContext, filter, filterStatus)) {
RefactoringParticipant participant = shared.get(descriptor);
if (participant != null) {
((ISharableParticipant) participant).addElement(element, arguments);
} else {
participant = descriptor.createParticipant();
if (fParticipantClass.isInstance(participant)) {
if (participant.initialize(processor, element, arguments)) {
participant.setDescriptor(descriptor);
result.add(participant);
if (participant instanceof ISharableParticipant)
shared.put(descriptor, participant);
}
} else {
status.addError(Messages.format(RefactoringCoreMessages.ParticipantExtensionPoint_participant_removed, descriptor.getName()));
RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.ParticipantExtensionPoint_wrong_type, new String[] { descriptor.getName(), fParticipantClass.getName() }));
iter.remove();
}
}
} else {
status.merge(filterStatus);
}
} catch (CoreException e) {
logMalfunctioningParticipant(status, descriptor, e);
iter.remove();
} catch (RuntimeException e) {
logMalfunctioningParticipant(status, descriptor, e);
iter.remove();
}
}
}
return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]);
}
use of org.eclipse.core.expressions.EvaluationContext in project translationstudio8 by heartsome.
the class ConverterCommandTrigger method openDialog.
private static void openDialog(IWorkbenchWindow window, IFile file, String commandId) {
IWorkbench workbench = window.getWorkbench();
ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
Command command = commandService.getCommand(commandId);
try {
EvaluationContext context = new EvaluationContext(null, IEvaluationContext.UNDEFINED_VARIABLE);
context.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, window);
if (file != null) {
StructuredSelection selection = new StructuredSelection(file);
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
}
command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, null, context));
} catch (ExecutionException e) {
LOGGER.error("", e);
} catch (NotDefinedException e) {
LOGGER.error("", e);
} catch (NotEnabledException e) {
LOGGER.error("", e);
} catch (NotHandledException e) {
LOGGER.error("", e);
}
}
use of org.eclipse.core.expressions.EvaluationContext in project dbeaver by serge-rider.
the class ActionUtils method runCommand.
public static void runCommand(String commandId, ISelection selection, IServiceLocator serviceLocator) {
if (commandId != null) {
try {
ICommandService commandService = serviceLocator.getService(ICommandService.class);
IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
boolean needContextPatch = false;
if (selection != null) {
needContextPatch = true;
if (serviceLocator instanceof IWorkbenchSite) {
final ISelection curSelection = ((IWorkbenchSite) serviceLocator).getSelectionProvider().getSelection();
if (curSelection instanceof IStructuredSelection && selection instanceof IStructuredSelection) {
if (((IStructuredSelection) curSelection).size() == ((IStructuredSelection) selection).size() && ((IStructuredSelection) curSelection).getFirstElement() == ((IStructuredSelection) selection).getFirstElement()) {
// The same selection
needContextPatch = false;
}
}
}
}
if (selection != null && needContextPatch) {
// Create new eval context
IEvaluationContext context = new EvaluationContext(handlerService.createContextSnapshot(false), selection);
if (serviceLocator instanceof IWorkbenchPartSite) {
context.addVariable(ISources.ACTIVE_PART_NAME, ((IWorkbenchPartSite) serviceLocator).getPart());
}
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
ParameterizedCommand pc = new ParameterizedCommand(command, null);
handlerService.executeCommandInContext(pc, null, context);
} else if (command != null && command.isEnabled()) {
handlerService.executeCommand(commandId, null);
}
}
} catch (Exception e) {
log.error("Can't execute command '" + commandId + "'", e);
}
}
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.text by eclipse.
the class CodeMiningProviderDescriptor method matches.
/**
* Returns true if the given viewer, editor matches the enabledWhen expression
* and false otherwise.
*
* @param viewer
* the viewer
* @param editor
* the editor
* @return true if the given viewer, editor matches the enabledWhen expression
* and false otherwise.
*/
public boolean matches(ISourceViewer viewer, ITextEditor editor) {
EvaluationContext context = new EvaluationContext(null, editor);
context.setAllowPluginActivation(true);
// $NON-NLS-1$
context.addVariable("viewer", viewer);
// $NON-NLS-1$
context.addVariable("editor", editor);
// $NON-NLS-1$
context.addVariable("editorInput", editor.getEditorInput());
try {
return fEnabledWhen.evaluate(context) == EvaluationResult.TRUE;
} catch (CoreException e) {
TextEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, "Error while 'enabledWhen' evaluation", e));
return false;
}
}
Aggregations