use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class OrientInstanceService method addSourceInstances.
/**
* @see InstanceService#addSourceInstances(InstanceCollection)
*/
@Override
public void addSourceInstances(InstanceCollection sourceInstances) {
notifyDatasetAboutToChange(DataSet.SOURCE);
final HaleStoreInstancesJob storeInstances = new HaleStoreInstancesJob("Load source instances into database", source, sourceInstances) {
@Override
protected void onComplete() {
notifyDatasetChanged(DataSet.SOURCE);
retransform();
}
};
// so instead, now the data is loaded in a progress dialog
try {
ThreadProgressMonitor.runWithProgressDialog(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
storeInstances.run(monitor);
}
}, true);
} catch (Exception e) {
log.error("Error starting process to load source data", e);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class IOWizard method performFinish.
/**
* @see Wizard#performFinish()
*
* @return <code>true</code> if executing the I/O provider was successful
*/
@Override
public boolean performFinish() {
if (getProvider() == null) {
return false;
}
if (!applyConfiguration()) {
return false;
}
// create default report
IOReporter defReport = provider.createReporter();
// validate and execute provider
try {
// validate configuration
provider.validate();
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
boolean isProjectResource = false;
if (actionId != null) {
// XXX instead move project resource to action?
ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId);
isProjectResource = factory.isProjectResource();
}
// prevent loading of duplicate resources
if (isProjectResource && provider instanceof ImportProvider && !getProviderFactory().allowDuplicateResource()) {
String currentResource = ((ImportProvider) provider).getSource().getLocation().toString();
URI currentAbsolute = URI.create(currentResource);
if (projectLoc != null && !currentAbsolute.isAbsolute()) {
currentAbsolute = projectLoc.resolve(currentAbsolute);
}
for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) {
Value otherResourceValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE);
if (otherResourceValue == null) {
continue;
}
String otherResource = otherResourceValue.as(String.class);
URI otherAbsolute = URI.create(otherResource);
if (projectLoc != null && !otherAbsolute.isAbsolute()) {
otherAbsolute = projectLoc.resolve(otherAbsolute);
}
String action = conf.getActionId();
// resource is already loaded into the project
if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) {
// check if the resource is loaded with a provider that
// allows duplicates
boolean allowDuplicate = false;
IOProviderDescriptor providerFactory = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (providerFactory != null) {
allowDuplicate = providerFactory.allowDuplicateResource();
}
if (!allowDuplicate) {
log.userError("Resource is already loaded. Loading duplicate resources is aborted!");
return false;
}
}
}
}
// enable provider internal caching
if (isProjectResource && provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setProvideCache();
}
IOReport report = execute(provider, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
// show message to user
if (report.isSuccess()) {
// let advisor handle results
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN);
try {
advisor.handleResults(getProvider());
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
log.userError("Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause());
return false;
} catch (Exception e) {
log.userError("Error processing results:\n" + e.getLocalizedMessage(), e);
return false;
}
// add to project service if necessary
if (isProjectResource)
ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider);
return true;
} else {
// error message
log.userError(report.getSummary() + "\nPlease see the report for details.");
return false;
}
} else
return true;
} catch (IOProviderConfigurationException e) {
// user feedback
log.userError("Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e);
return false;
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class URLSource method runDetectContentType.
/**
* Run content type detection.
*/
protected void runDetectContentType() {
try {
getPage().getWizard().getContainer().run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Detect content type", IProgressMonitor.UNKNOWN);
final IContentType detected = detectContentType();
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (detected != null) {
types.setSelection(new StructuredSelection(detected));
getPage().setMessage(MessageFormat.format("Detected {0} as content type", detected.getName()), DialogPage.INFORMATION);
updateState(true);
} else {
types.setSelection(new StructuredSelection());
getPage().setMessage("Could not detect content type. The resource might be not available or it has no matching content type.", DialogPage.WARNING);
updateState(true);
}
}
});
monitor.done();
}
});
} catch (Throwable t) {
getPage().setErrorMessage("Starting the task to detect the content type failed");
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class ExportGraphAction method run.
/**
* @see Action#run()
*/
@Override
public void run() {
FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
// XXX if called from TTreeExporter during transformation, the active
// shell may be null!
dialog.setOverwrite(true);
dialog.setText("Export graph to file");
String[] imageExtensions = ImageIO.getWriterFileSuffixes();
StringBuffer extensions = new StringBuffer("*.svg;*.gv;*.dot");
for (String imageExt : imageExtensions) {
extensions.append(";*.");
extensions.append(imageExt);
}
dialog.setFilterExtensions(new String[] { extensions.toString() });
dialog.setFilterNames(new String[] { "Image, SVG or dot file (" + extensions + ")" });
String fileName = dialog.open();
if (fileName != null) {
final File file = new File(fileName);
// //XXX use an off-screen graph (testing)
// OffscreenGraph graph = new OffscreenGraph(1000, 1000) {
//
// @Override
// protected void configureViewer(GraphViewer viewer) {
// viewer.setContentProvider(RenderAction.this.viewer.getContentProvider());
// viewer.setLabelProvider(RenderAction.this.viewer.getLabelProvider());
// viewer.setInput(RenderAction.this.viewer.getInput());
// viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT), false);
// }
// };
// get the graph
final Graph graph = viewer.getGraphControl();
final String ext = FilenameUtils.getExtension(file.getAbsolutePath());
final IFigure root = graph.getRootLayer();
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
try {
progress.run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
if (ext.equalsIgnoreCase("gv") || ext.equalsIgnoreCase("dot")) {
OffscreenGraph.saveDot(graph, out);
} else // else if (ext.equalsIgnoreCase("svg")) {
// OffscreenGraph.saveSVG(root, out);
// }
{
OffscreenGraph.saveImage(root, out, ext);
}
} catch (Throwable e) {
log.userError("Error saving graph to file", e);
}
}
});
} catch (Throwable e) {
log.error("Error launching graph export", e);
}
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class TransformDataWizardSourcePage method createControl.
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
Composite content = new Composite(parent, SWT.NONE);
content.setLayout(GridLayoutFactory.swtDefaults().create());
final ListViewer listViewer = new ListViewer(content);
listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
if (!useProjectData) {
Button addButton = new Button(content, SWT.PUSH);
addButton.setText("Add source file");
addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
InstanceImportWizard importWizard = new InstanceImportWizard();
TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
// specifying null as actionId results in no call to
// ProjectService.rememberIO
importWizard.setAdvisor(advisor, null);
if (new HaleWizardDialog(getShell(), importWizard).open() == Dialog.OK) {
if (advisor.getInstances() != null) {
sourceCollections.add(advisor.getInstances());
listViewer.add(advisor.getLocation());
getContainer().updateButtons();
}
}
}
});
} else {
// initialize project source data
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN);
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
final List<URI> locations = new ArrayList<>();
for (Resource resource : ps.getResources()) {
if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
// resource is source data
IOConfiguration conf = resource.copyConfiguration(true);
TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
if (advisor.getInstances() != null) {
sourceCollections.add(advisor.getInstances());
locations.add(advisor.getLocation());
}
}
}
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
for (URI location : locations) {
listViewer.add(location);
}
}
});
monitor.done();
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, false);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
setControl(content);
}
Aggregations