use of org.eclipse.cdt.core.model.CModelException in project linuxtools by eclipse.
the class SystemTapLaunchShortcut method chooseUnit.
/**
* Creates a dialog that prompts the user to select from the given list of
* ICElements
*
* @param list
* : list of ICElements
* @return
*/
private Object[] chooseUnit(List<ICContainer> list, int numberOfValidFiles) {
ListTreeContentProvider prov = new ListTreeContentProvider();
RuledTreeSelectionDialog dialog = new RuledTreeSelectionDialog(getActiveWorkbenchShell(), new WorkbenchLabelProvider(), prov);
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapLaunchShortcut.SelectFiles"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapLaunchShortcut.SelectFilesMsg"));
dialog.setInput(list);
dialog.setHelpAvailable(false);
dialog.setStatusLineAboveButtons(false);
dialog.setEmptyListMessage(Messages.getString(// $NON-NLS-1$
"SystemTapLaunchShortcut.NoFiles"));
dialog.setContainerMode(true);
Object[] topLevel = prov.findElements(list);
dialog.setInitialSelections(topLevel);
dialog.setSize(cap(topLevel.length * 10, 30, 55), cap((int) (topLevel.length * 1.5), 3, 13));
dialog.create();
Button okButton = dialog.getOkButton();
Object[] result = null;
if (testMode) {
okButton.setSelection(true);
result = list.toArray();
ArrayList<Object> output = new ArrayList<>();
try {
for (Object obj : result) {
if (obj instanceof ICContainer) {
ICElement[] array = ((ICContainer) obj).getChildren();
for (ICElement c : array) {
if (!(validElement(c))) {
continue;
}
if (c.getElementName().contains(MAIN_FUNC_NAME) && !output.contains(c)) {
output.add(c);
}
}
}
}
if (output.size() >= numberOfValidFiles) {
output.clear();
output.add(USER_SELECTED_ALL);
}
} catch (CModelException e) {
e.printStackTrace();
}
result = output.toArray();
} else {
if (dialog.open() == Window.CANCEL) {
return null;
}
result = dialog.getResult();
}
if (result == null) {
return null;
}
ArrayList<Object> output = new ArrayList<>();
try {
for (Object obj : result) {
if (obj instanceof ICContainer) {
ICElement[] array = ((ICContainer) obj).getChildren();
for (ICElement c : array) {
if (!(validElement(c))) {
continue;
}
if (!output.contains(c)) {
output.add(c);
}
}
} else if ((obj instanceof ICElement) && validElement((ICElement) obj) && !output.contains(obj)) {
output.add(obj);
}
}
if (output.size() >= numberOfValidFiles) {
output.clear();
output.add(USER_SELECTED_ALL);
}
} catch (CModelException e) {
e.printStackTrace();
}
return output.toArray();
}
use of org.eclipse.cdt.core.model.CModelException in project linuxtools by eclipse.
the class ProfileLaunchShortcut method searchAndLaunch.
/**
* Search and launch binary.
*
* @param elements Binaries to search.
* @param mode Launch mode.
*/
private void searchAndLaunch(final Object[] elements, String mode) {
if (elements != null && elements.length > 0) {
IBinary bin = null;
if (elements.length == 1 && elements[0] instanceof IBinary) {
bin = (IBinary) elements[0];
} else {
final List<IBinary> results = new ArrayList<>();
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getActiveWorkbenchShell());
IRunnableWithProgress runnable = pm -> {
int nElements = elements.length;
pm.beginTask(Messages.ProfileLaunchShortcut_Looking_for_executables, nElements);
try {
IProgressMonitor sub = SubMonitor.convert(pm, 1);
for (int i = 0; i < nElements; i++) {
if (elements[i] instanceof IAdaptable) {
IResource r = ((IAdaptable) elements[i]).getAdapter(IResource.class);
if (r != null) {
ICProject cproject = CoreModel.getDefault().create(r.getProject());
if (cproject != null) {
try {
IBinary[] bins = cproject.getBinaryContainer().getBinaries();
for (IBinary bin1 : bins) {
if (bin1.isExecutable()) {
results.add(bin1);
}
}
} catch (CModelException e) {
// TODO should this be simply ignored ?
}
}
}
}
if (pm.isCanceled()) {
throw new InterruptedException();
}
sub.done();
}
} finally {
pm.done();
}
};
try {
dialog.run(true, true, runnable);
} catch (InterruptedException e) {
return;
} catch (InvocationTargetException e) {
handleFail(e.getMessage());
return;
}
int count = results.size();
if (count == 0) {
handleFail(Messages.ProfileLaunchShortcut_Binary_not_found);
} else if (count > 1) {
bin = chooseBinary(results, mode);
} else {
bin = results.get(0);
}
}
if (bin != null) {
launch(bin, mode);
}
} else {
handleFail(Messages.ProfileLaunchShortcut_no_project_selected);
}
}
Aggregations