use of org.eclipse.core.commands.ExecutionException in project AutoRefactor by JnRouvignac.
the class ChooseRefactoringsWizardHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final Shell shell = HandlerUtil.getActiveShell(event);
try {
// Retrieve the targeted java element before the menu item is disposed by the framework
final Wizard wizard = new ChooseRefactoringsWizard(AutoRefactorHandler.getSelectedJavaElements(event));
final WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.open();
} catch (final Exception e) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
openInformation(shell, "Info", "An error has occurred:\n\n" + sw.toString());
}
});
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project linuxtools by eclipse.
the class RunScriptHandler method isGuru.
/**
* Checks the current script to determine if guru mode is required in order to run. This is determined
* by the presence of embedded C.
* @return True if the script contains embedded C code.
*/
private boolean isGuru() throws ExecutionException {
File f = new File(fileName);
try (FileReader fr = new FileReader(f)) {
int curr = 0;
int prev = 0;
boolean front = false;
boolean embedded = false;
boolean inLineComment = false;
boolean inBlockComment = false;
while (-1 != (curr = fr.read())) {
if (!inLineComment && !inBlockComment && prev == '%' && curr == '{') {
front = true;
} else if (!inLineComment && !inBlockComment && prev == '%' && curr == '}' && front) {
embedded = true;
break;
} else if (!inBlockComment && ((prev == '/' && curr == '/') || curr == '#')) {
inLineComment = true;
} else if (!inLineComment && prev == '/' && curr == '*') {
inBlockComment = true;
} else if (curr == '\n') {
inLineComment = false;
} else if (prev == '*' && curr == '/') {
inBlockComment = false;
}
prev = curr;
}
if (embedded) {
return true;
}
} catch (FileNotFoundException fnfe) {
// $NON-NLS-1$
throw new ExecutionException(Localization.getString("RunScriptHandler.couldNotOpenScriptFile"), fnfe);
} catch (IOException ie) {
// $NON-NLS-1$
throw new ExecutionException(Localization.getString("RunScriptHandler.fileIOError"), ie);
}
return false;
}
use of org.eclipse.core.commands.ExecutionException in project yamcs-studio by yamcs.
the class AddCommentHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
Shell shell = HandlerUtil.getActiveShell(event);
if (sel != null && sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
if (selection.isEmpty()) {
return null;
}
// Populate with text of first record. But only if single selection
String initialValue = "";
if (selection.size() == 1) {
CommandHistoryRecord rec = (CommandHistoryRecord) selection.getFirstElement();
String existingComment = rec.getTextForColumn("Comment", false);
if (existingComment != null) {
initialValue = existingComment;
}
}
String dialogMessage;
if (selection.size() == 1) {
dialogMessage = "Add a comment for this command";
} else {
dialogMessage = "Add a comment for the " + selection.size() + " selected commands";
}
IInputValidator validator = newText -> null;
InputDialog commentDialog = new InputDialog(shell, "Add Comment", dialogMessage, initialValue, validator) {
@Override
protected int getInputTextStyle() {
return SWT.MULTI | SWT.BORDER | SWT.V_SCROLL;
}
@Override
protected Control createDialogArea(Composite parent) {
Control res = super.createDialogArea(parent);
((GridData) this.getText().getLayoutData()).heightHint = 4 * this.getText().getLineHeight();
return res;
}
};
int commentResult = commentDialog.open();
if (commentResult == Window.OK) {
String newComment = commentDialog.getValue();
CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
// TODO improve me. Bundle into only one error message
// Or even better: one api call.
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
catalogue.updateCommandComment("realtime", rec.getCommandId(), newComment).exceptionally(t -> {
Display.getDefault().asyncExec(() -> {
MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
dialog.setText("Comment Update");
dialog.setMessage("Comment has not been updated. Details: " + t.getMessage());
// open dialog and await user selection
dialog.open();
});
return null;
});
}
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project yamcs-studio by yamcs.
the class ExportCommandStackHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Get current command stack
Collection<StackedCommand> scs = org.yamcs.studio.commanding.stack.CommandStack.getInstance().getCommands();
if (scs == null || scs.isEmpty()) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Export Command Stack", "Current command stack is empty. No command to export.");
return null;
}
FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
dialog.setFilterExtensions(new String[] { "*.xml" });
// dialog.setFilterPath("c:\\temp");
String exportFile = dialog.open();
System.out.println("export file choosen: " + exportFile);
if (exportFile == null) {
// cancelled
return null;
}
// Build model
org.yamcs.studio.commanding.stack.xml.CommandStack exportCommandStack = new org.yamcs.studio.commanding.stack.xml.CommandStack();
List<org.yamcs.studio.commanding.stack.xml.CommandStack.Command> exportedCommands = exportCommandStack.getCommand();
for (StackedCommand sc : scs) {
org.yamcs.studio.commanding.stack.xml.CommandStack.Command c = new org.yamcs.studio.commanding.stack.xml.CommandStack.Command();
c.setQualifiedName(sc.getMetaCommand().getQualifiedName());
c.setSelectedAlias(sc.getSelectedAlias());
c.setComment(sc.getComment());
exportedCommands.add(c);
List<CommandArgument> cas = c.getCommandArgument();
Iterator<Entry<ArgumentInfo, String>> it = sc.getAssignments().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<ArgumentInfo, String> pair = it.next();
String argName = pair.getKey().getName();
String argValue = pair.getValue();
CommandArgument ca = new CommandArgument();
ca.setArgumentName(argName);
ca.setArgumentValue(argValue);
cas.add(ca);
}
}
// Write model to file
try {
File file = new File(exportFile);
JAXBContext jaxbContext = JAXBContext.newInstance(org.yamcs.studio.commanding.stack.xml.CommandStack.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(exportCommandStack, file);
jaxbMarshaller.marshal(exportCommandStack, System.out);
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Export Command Stack", "Unable to perform command stack export.\nDetails:" + e.getMessage());
return null;
}
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Export Command Stack", "Command stack exported successfully.");
return null;
}
use of org.eclipse.core.commands.ExecutionException in project yamcs-studio by yamcs.
the class IssueCommandHandler method issueCommand.
private void issueCommand(Shell activeShell, CommandStackView view, StackedCommand command) throws ExecutionException {
IssueCommandRequest req = command.toIssueCommandRequest().build();
CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
String qname;
try {
qname = command.getSelectedAliasEncoded();
} catch (UnsupportedEncodingException e1) {
throw new ExecutionException(e1.getMessage());
}
catalogue.sendCommand("realtime", qname, req).whenComplete((data, exc) -> {
if (exc == null) {
Display.getDefault().asyncExec(() -> {
log.info(String.format("Command issued. %s", req));
command.setStackedState(StackedState.ISSUED);
view.selectActiveCommand();
view.refreshState();
});
} else {
Display.getDefault().asyncExec(() -> {
command.setStackedState(StackedState.REJECTED);
view.refreshState();
});
}
});
}
Aggregations