本文整理汇总了Java中org.eclipse.ui.handlers.HandlerUtil.getCurrentSelectionChecked方法的典型用法代码示例。如果您正苦于以下问题:Java HandlerUtil.getCurrentSelectionChecked方法的具体用法?Java HandlerUtil.getCurrentSelectionChecked怎么用?Java HandlerUtil.getCurrentSelectionChecked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.handlers.HandlerUtil
的用法示例。
在下文中一共展示了HandlerUtil.getCurrentSelectionChecked方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
Description desc = (Description) selection.getFirstElement();
if (desc.isTest() && view.testsExecutionStatus.hasFailed(desc)) {
Throwable failureException = view.testsExecutionStatus.getFailure(desc).getException();
if (failureException instanceof ComparisonFailure) {
ComparisonFailure cf = (ComparisonFailure) failureException;
// display comparison view
displayComparisonView(cf, desc);
}
}
return null;
}
示例2: getProjects
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public static List<IProject> getProjects(ExecutionEvent event) throws ExecutionException {
List<IProject> projects = new ArrayList<>();
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
for (Object selected : structuredSelection.toList()) {
IProject project = AdapterUtil.adapt(selected, IProject.class);
if (project != null) {
projects.add(project);
}
}
}
return projects;
}
示例3: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException
{
/*
* Try to get the spec from active navigator if any
*/
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection != null && selection instanceof IStructuredSelection
&& ((IStructuredSelection) selection).size() == 1)
{
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof Model)
{
Map<String, String> parameters = new HashMap<String, String>();
// fill the model name for the handler
parameters.put(OpenModelHandler.PARAM_MODEL_NAME, ((Model) selected).getName());
// delegate the call to the open model handler
UIHelper.runCommand(OpenModelHandler.COMMAND_ID, parameters);
}
}
return null;
}
示例4: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
/*
* Try to get the spec from active navigator if any
*/
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection != null && selection instanceof IStructuredSelection
&& ((IStructuredSelection) selection).size() == 1) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof ModelContentProvider.Group) {
// Convert the group to its corresponding spec
selected = ((Group) selected).getSpec();
}
if (selected instanceof Spec) {
final Map<String, String> parameters = new HashMap<String, String>();
// fill the spec name for the handler
parameters.put(NewModelHandler.PARAM_SPEC_NAME, ((Spec) selected).getName());
// delegate the call to the new model handler
UIHelper.runCommand(NewModelHandler.COMMAND_ID, parameters);
}
}
return null;
}
示例5: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil
.getCurrentSelectionChecked(event);
try {
breakpointUtils.toggleBreakpoints(selection);
} catch (CoreException e) {
throw new ExecutionException("Error while toggling breakpoint.", e);
}
return null;
}
示例6: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
try {
breakpointUtils.toggleBreakpoints(selection);
} catch (CoreException e) {
throw new ExecutionException("Error while toggling breakpoint.", e);
}
return null;
}
示例7: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
/**
* When called will check if provided data contains {@link Description test description} with failed status stored
* in {@link N4IDEXpectView test view}. If that holds, will generate data for bug report in a console view,
* otherwise will show message to reconfigure and rerun Xpect tests.
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
Description desc = (Description) selection.getFirstElement();
// handle failed suite
if (desc.isSuite()) {
final N4IDEXpectView finalview = view;
boolean suitePassed = desc.getChildren().stream()
.noneMatch(childDescription -> finalview.testsExecutionStatus.hasFailed(childDescription));
if (suitePassed) {
XpectFileContentsUtil.getXpectFileContentAccess(desc).ifPresent(
xpectFielContentAccess -> {
if (xpectFielContentAccess.containsFixme()) {
generateAndDisplayReport(
N4IDEXpectFileNameUtil.getSuiteName(desc),
xpectFielContentAccess.getContetns());
}
});
} else {
XpectConsole console = ConsoleDisplayMgr.getOrCreate("generated bug for "
+ N4IDEXpectFileNameUtil.getSuiteName(desc));
console.clear();
String ls = System.lineSeparator();
console.log("Suite must be passing and contain XPECT FIXME marker to be submited bug report. Please :"
+ ls + " - fix failing tests" + ls + " - mark test in question with XPECT FIXME");
}
}
return null;
}
示例8: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException
{
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection != null && selection instanceof IStructuredSelection)
{
// model file
final Model model = (Model) ((IStructuredSelection) selection).getFirstElement();
// a) fail if model is in use
if (model.isRunning()) {
MessageDialog.openError(UIHelper.getShellProvider().getShell(), "Could not rename models",
"Could not rename the model " + model.getName()
+ ", because it is being model checked.");
return null;
}
if (model.isSnapshot()) {
MessageDialog.openError(UIHelper.getShellProvider().getShell(), "Could not rename model",
"Could not rename the model " + model.getName()
+ ", because it is a snapshot.");
return null;
}
// b) open dialog prompting for new model name
final IInputValidator modelNameInputValidator = new ModelNameValidator(model.getSpec());
final InputDialog dialog = new InputDialog(UIHelper.getShell(), "Rename model...",
"Please input the new name of the model", model.getName(), modelNameInputValidator);
dialog.setBlockOnOpen(true);
if(dialog.open() == Window.OK) {
// c) close model editor if open
final IEditorPart editor = model.getAdapter(ModelEditor.class);
if(editor != null) {
reopenModelEditorAfterRename = true;
UIHelper.getActivePage().closeEditor(editor, true);
}
final Job j = new ToolboxJob("Renaming model...") {
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
// d) rename
final String newModelName = dialog.getValue();
model.rename(newModelName);
// e) reopen (in UI thread)
if (reopenModelEditorAfterRename) {
UIHelper.runUIAsync(new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(OpenModelHandler.PARAM_MODEL_NAME, newModelName);
UIHelper.runCommand(OpenModelHandler.COMMAND_ID, parameters);
}
});
}
return Status.OK_STATUS;
}
};
j.schedule();
}
}
return null;
}
示例9: execute
import org.eclipse.ui.handlers.HandlerUtil; //导入方法依赖的package包/类
/**
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final TLCSpec spec = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class);
Model model = null;
/*
* First try to get the model from the parameters. It is an optional
* parameter, so it may not have been set.
*/
final String paramModelName = (String) event.getParameter(PARAM_MODEL_NAME);
if (paramModelName != null) {
// The name is given which means the user clicked the main menu
// instead of the spec explorer. Under the constraint that only ever
// a single spec can be open, lookup the current spec to eventually
// get the corresponding model.
model = spec.getModel(paramModelName);
} else {
/*
* No parameter try to get it from active navigator if any
*/
final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection != null && selection instanceof IStructuredSelection) {
// model
model = (Model) ((IStructuredSelection) selection).getFirstElement();
}
}
if (model != null) {
final InputDialog dialog = new InputDialog(UIHelper.getShellProvider().getShell(), "Clone model...",
"Please input the new name of the model", spec.getModelNameSuggestion(model), new ModelNameValidator(spec));
dialog.setBlockOnOpen(true);
if (dialog.open() == Window.OK) {
final String usersChosenName = dialog.getValue();
if (model.copy(usersChosenName) == null) {
throw new ExecutionException(
"Failed to copy with name " + usersChosenName + " from model " + model.getName());
}
// Open the previously created model
final Map<String, String> parameters = new HashMap<String, String>();
parameters.put(OpenModelHandler.PARAM_MODEL_NAME, usersChosenName);
UIHelper.runCommand(OpenModelHandler.COMMAND_ID, parameters);
}
}
return null;
}