use of org.eclipse.e4.ui.di.Focus in project portfolio by buchen.
the class ImportPDFHandler method doExecute.
/* package */
void doExecute(MPart part, Shell shell, boolean isLegacyMode) {
Client client = MenuHelper.getActiveClient(part);
if (client == null)
return;
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
fileDialog.setText(Messages.PDFImportWizardAssistant);
fileDialog.setFilterNames(new String[] { Messages.PDFImportFilterName });
// $NON-NLS-1$
fileDialog.setFilterExtensions(new String[] { "*.pdf" });
fileDialog.open();
String[] filenames = fileDialog.getFileNames();
if (filenames.length == 0)
return;
List<Extractor.InputFile> files = new ArrayList<>();
for (String filename : filenames) files.add(new PDFInputFile(new File(fileDialog.getFilterPath(), filename)));
IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
try {
IRunnableWithProgress operation = monitor -> {
monitor.beginTask(Messages.PDFImportWizardMsgExtracting, files.size());
for (Extractor.InputFile inputFile : files) {
monitor.setTaskName(inputFile.getName());
try {
((PDFInputFile) inputFile).parse();
} catch (IOException e) {
throw new IllegalArgumentException(MessageFormat.format(Messages.PDFImportErrorParsingDocument, inputFile.getName()), e);
}
monitor.worked(1);
}
// if we just run this async, then the main window on macOS does
// not regain focus and the menus are not usable
new // $NON-NLS-1$
Job(// $NON-NLS-1$
"") {
@Override
protected IStatus run(IProgressMonitor monitor) {
shell.getDisplay().asyncExec(() -> openWizard(shell, client, files, preferences, isLegacyMode));
return Status.OK_STATUS;
}
}.schedule(50);
};
new ProgressMonitorDialog(shell).run(true, true, operation);
} catch (IllegalArgumentException | InvocationTargetException | InterruptedException e) {
PortfolioPlugin.log(e);
String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
MessageDialog.openError(shell, Messages.LabelError, message);
}
}
use of org.eclipse.e4.ui.di.Focus in project AGREE by loonwerks.
the class VariablesView method beforeCreateStepArguments.
@Inject
@Optional
void beforeCreateStepArguments(@UIEventTopic(SimulatorUIEvents.BEFORE_STEP_FORWARD) final BeforeStepForwardEvent event) {
// Take the focus away from cell editors widgets
if (treeViewer != null) {
final Control focusControl = Display.getCurrent().getFocusControl();
final Tree tree = treeViewer.getTree();
for (Control c = focusControl; c != null; c = c.getParent()) {
if (c == tree) {
treeViewer.getTree().forceFocus();
break;
}
}
}
// Cancel the step
if (elementToConstraintErrorMap.size() > 0) {
event.cancelStep(new Throwable("One or more user constraints is invalid."));
}
}
use of org.eclipse.e4.ui.di.Focus in project portfolio by buchen.
the class ImportPDFHandler method runImportWithFiles.
public static void runImportWithFiles(PortfolioPart part, Shell shell, Client client, Account account, Portfolio portfolio, List<File> files) {
files.sort((File lhs, File rhs) -> {
int modDiff = (int) (lhs.lastModified() - rhs.lastModified());
return modDiff == 0 ? lhs.getPath().compareTo(rhs.getPath()) : modDiff;
});
IPreferenceStore preferences = part.getPreferenceStore();
try {
IRunnableWithProgress operation = monitor -> {
PDFImportAssistant assistent = new PDFImportAssistant(client, files);
Map<File, List<Exception>> errors = new HashMap<>();
Map<Extractor, List<Extractor.Item>> result = assistent.run(monitor, errors);
// if we just run this async, then the main window on macOS does
// not regain focus and the menus are not usable
new // $NON-NLS-1$
Job(// $NON-NLS-1$
"") {
@Override
protected IStatus run(IProgressMonitor monitor) {
shell.getDisplay().asyncExec(() -> {
ImportExtractedItemsWizard wizard = new ImportExtractedItemsWizard(client, preferences, result, errors);
if (account != null)
wizard.setTarget(account);
if (portfolio != null)
wizard.setTarget(portfolio);
Dialog wizwardDialog = new WizardDialog(shell, wizard);
wizwardDialog.open();
});
return Status.OK_STATUS;
}
}.schedule(50);
};
new ProgressMonitorDialog(shell).run(true, true, operation);
} catch (IllegalArgumentException | InvocationTargetException | InterruptedException e) {
PortfolioPlugin.log(e);
String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
MessageDialog.openError(shell, Messages.LabelError, message);
}
}
use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.
the class PartActivationHistory method getNextActivationCandidate.
MPart getNextActivationCandidate(Collection<MPart> validParts, MPart part) {
MArea area = isInArea(part);
if (area != null) {
// focus should stay in the area if possible
MPart candidate = getSiblingActivationCandidate(part);
if (candidate != null) {
return candidate;
}
// no sibling candidate, find another part in the area to activate
candidate = findActivationCandidate(modelService.findElements(area, null, MPart.class), part);
if (candidate != null) {
return candidate;
}
}
// check activation history, since the history is global, we need to filter it down first
Collection<MPart> validCandidates = new ArrayList<>();
for (MPart validPart : generalActivationHistory) {
if (validParts.contains(validPart)) {
validCandidates.add(validPart);
}
}
MPart candidate = findActivationCandidate(validCandidates, part);
return candidate == null ? getActivationCandidate(part) : candidate;
}
use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.
the class SplitHost method setFocus.
@Focus
void setFocus() {
MPart ap = findInnerActive(myPart);
if (ap == null) {
if (Policy.DEBUG_FOCUS) {
// $NON-NLS-1$
WorkbenchSWTActivator.trace(// $NON-NLS-1$
Policy.DEBUG_FOCUS_FLAG, // $NON-NLS-1$
"Focus not set, no selected element in: " + myPart, new IllegalStateException());
}
return;
}
Control ctrl = (Control) ap.getWidget();
Object object = ap.getObject();
if (object != null && ctrl != null && !ctrl.isDisposed()) {
ContextInjectionFactory.invoke(object, Focus.class, ap.getContext(), null);
} else if (Policy.DEBUG_FOCUS) {
WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Focus not set, object is null or widget is disposed: " + object, // $NON-NLS-1$
new IllegalStateException());
}
}
Aggregations