List of usage examples for org.eclipse.jface.operation ModalContext checkCanceled
public static void checkCanceled(IProgressMonitor monitor) throws InterruptedException
InterruptedException
if it has been canceled. From source file:org.eclipse.ui.internal.wizards.datatransfer.FileSystemExportOperation.java
License:Open Source License
/** * Export the passed file to the specified location * * @param file org.eclipse.core.resources.IFile * @param location org.eclipse.core.runtime.IPath *//*from ww w . j a v a 2 s . com*/ protected void exportFile(IFile file, IPath location) throws InterruptedException { IPath fullPath = location.append(file.getName()); monitor.subTask(file.getFullPath().toString()); String properPathString = fullPath.toOSString(); File targetFile = new File(properPathString); if (targetFile.exists()) { if (!targetFile.canWrite()) { errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind(DataTransferMessages.DataTransfer_cannotOverwrite, targetFile.getAbsolutePath()), null)); monitor.worked(1); return; } if (overwriteState == OVERWRITE_NONE) { return; } if (overwriteState != OVERWRITE_ALL) { String overwriteAnswer = overwriteCallback.queryOverwrite(properPathString); if (overwriteAnswer.equals(IOverwriteQuery.CANCEL)) { throw new InterruptedException(); } if (overwriteAnswer.equals(IOverwriteQuery.NO)) { monitor.worked(1); return; } if (overwriteAnswer.equals(IOverwriteQuery.NO_ALL)) { monitor.worked(1); overwriteState = OVERWRITE_NONE; return; } if (overwriteAnswer.equals(IOverwriteQuery.ALL)) { overwriteState = OVERWRITE_ALL; } } } try { exporter.write(file, fullPath); } catch (IOException e) { errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind(DataTransferMessages.DataTransfer_errorExporting, fullPath, e.getMessage()), e)); } catch (CoreException e) { errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind(DataTransferMessages.DataTransfer_errorExporting, fullPath, e.getMessage()), e)); } monitor.worked(1); ModalContext.checkCanceled(monitor); }
From source file:org.eclipse.ui.wizards.datatransfer.PopulateRootOperation.java
License:Open Source License
/** * Creates and returns a <code>FileSystemElement</code> if the specified * file system object merits one. The criteria for this are: * - if the file system object is a container then it must have either a * child container or an associated file * - if the file system object is a file then it must have an extension * suitable for selection/*from w w w . j av a 2s. c o m*/ * recurse down for depth to populate children */ protected FileSystemElement createElement(FileSystemElement parent, Object fileSystemObject, int depth) throws InterruptedException { ModalContext.checkCanceled(monitor); boolean isContainer = provider.isFolder(fileSystemObject); String elementLabel = parent == null ? provider.getFullPath(fileSystemObject) : provider.getLabel(fileSystemObject); MinimizedFileSystemElement result = new MinimizedFileSystemElement(elementLabel, parent, isContainer); result.setFileSystemObject(fileSystemObject); if (isContainer) { if (depth > 0) { List children = provider.getChildren(fileSystemObject); if (children == null) { children = new ArrayList(1); } Iterator childrenEnum = children.iterator(); while (childrenEnum.hasNext()) { createElement(result, childrenEnum.next(), depth - 1); } result.setPopulated(); } } return result; }
From source file:org.eclipse.ui.wizards.datatransfer.SelectFilesOperation.java
License:Open Source License
/** * Creates and returns a <code>FileSystemElement</code> if the specified * file system object merits one. The criteria for this are: * - if the file system object is a container then it must have either a * child container or an associated file * - if the file system object is a file then it must have an extension * suitable for selection/* w w w. ja v a 2s .co m*/ */ protected FileSystemElement createElement(FileSystemElement parent, Object fileSystemObject) throws InterruptedException { ModalContext.checkCanceled(monitor); boolean isContainer = provider.isFolder(fileSystemObject); String elementLabel = parent == null ? provider.getFullPath(fileSystemObject) : provider.getLabel(fileSystemObject); if (!isContainer && !hasDesiredExtension(elementLabel)) { return null; } FileSystemElement result = new FileSystemElement(elementLabel, parent, isContainer); result.setFileSystemObject(fileSystemObject); if (isContainer) { boolean haveChildOrFile = false; List children = provider.getChildren(fileSystemObject); if (children == null) { children = new ArrayList(1); } Iterator childrenEnum = children.iterator(); while (childrenEnum.hasNext()) { if (createElement(result, childrenEnum.next()) != null) { haveChildOrFile = true; } } if (!haveChildOrFile && parent != null) { parent.removeFolder(result); result = null; } } return result; }
From source file:org.jboss.tools.windup.ui.internal.archiver.ArchiveFileExportOperation.java
License:Open Source License
/** * <p>//w w w . j av a 2 s . c o m * Export the passed resource to the destination archive * </p> * * @param fileToExport {@link File} to export * @param leadupDepth the number of directory levels to be included in the path including the {@link File} itself. */ private void exportResource(File fileToExport, IPath relativeTo) throws InterruptedException { if (fileToExport.exists()) { /* * if the File to export is a file export it else if File is a directory recursivly export all of it's childre */ if (fileToExport.isFile()) { String destinationName = createDestinationName(fileToExport, relativeTo); this.monitor.subTask(destinationName); try { this.exporter.write(fileToExport, destinationName); } catch (IOException e) { addError(NLS.bind(Messages.ArchiveFileExport_errorExporting, fileToExport.getPath(), e.getMessage()), e); } monitor.worked(1); ModalContext.checkCanceled(monitor); } else { // create an entry for empty containers File[] children = fileToExport.listFiles(); if (children.length == 0) { String destinationName = createDestinationName(fileToExport, relativeTo); try { this.exporter.write(fileToExport, destinationName + IPath.SEPARATOR); } catch (IOException e) { addError(NLS.bind(Messages.ArchiveFileExport_errorExporting, fileToExport.getPath(), e.getMessage()), e); } } for (int i = 0; i < children.length; i++) { exportResource(children[i], relativeTo); } } } }
From source file:org.marketcetera.photon.commons.ui.workbench.AbstractSelectionHandler.java
@Override public void executeSafely(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); final List<T> selected = Collections.synchronizedList(Lists.<T>newArrayList()); for (Object item : selection.toList()) { if (mClazz.isInstance(item)) { T cast = mClazz.cast(item);/*from w w w . j av a 2 s. co m*/ if (mPredicate.apply(cast)) { selected.add(cast); } } } if (selected.isEmpty()) { return; } final IRunnableWithProgress operation = JFaceUtils .safeRunnableWithProgress(new IUnsafeRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws Exception { SubMonitor progress = SubMonitor.convert(monitor, selected.size()); for (T item : selected) { ModalContext.checkCanceled(progress); process(item, progress.newChild(1)); } } }); ProgressUtils.runModalWithErrorDialog(HandlerUtil.getActiveWorkbenchWindowChecked(event), operation, mFailureMessage); }
From source file:org.marketcetera.photon.internal.strategy.engine.ui.workbench.handlers.RefreshHandler.java
@Override protected void executeSafely(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); final List<StrategyEngine> engines = Collections.synchronizedList(Lists.<StrategyEngine>newArrayList()); final List<DeployedStrategy> strategies = Collections .synchronizedList(Lists.<DeployedStrategy>newArrayList()); for (Object item : selection.toList()) { if (item instanceof StrategyEngine) { engines.add((StrategyEngine) item); } else if (item instanceof DeployedStrategy) { DeployedStrategy strategy = (DeployedStrategy) item; /*/*from ww w .j a v a 2 s . c o m*/ * Optimization to not refresh strategies that are going to be * refreshed with the engine. */ if (!engines.contains(strategy.getEngine())) { strategies.add(strategy); } } } if (engines.isEmpty() && strategies.isEmpty()) { return; } final IRunnableWithProgress operation = JFaceUtils .safeRunnableWithProgress(new IUnsafeRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws Exception { /* * Guess that refreshing an engine will take roughly 3 * times as long as refreshing a single strategy. */ int engineWork = 3; SubMonitor progress = SubMonitor.convert(monitor, 3 * engines.size() + strategies.size()); for (StrategyEngine engine : engines) { ModalContext.checkCanceled(progress); progress.setTaskName( Messages.REFRESH_HANDLER_REFRESH_ENGINE__TASK_NAME.getText(engine.getName())); engine.getConnection().refresh(); progress.worked(engineWork); } for (DeployedStrategy strategy : strategies) { ModalContext.checkCanceled(progress); progress.setTaskName(Messages.REFRESH_HANDLER_REFRESH_STRATEGY__TASK_NAME .getText(strategy.getInstanceName(), strategy.getEngine().getName())); strategy.getEngine().getConnection().refresh(strategy); progress.worked(1); } } }); ProgressUtils.runModalWithErrorDialog(HandlerUtil.getActiveWorkbenchWindowChecked(event), operation, Messages.REFRESH_HANDLER_FAILED); }
From source file:org.talend.core.ui.export.ArchiveFileExportOperationFullPath.java
License:Open Source License
/** * Export the passed resource to the destination .zip. * //from www. ja va2 s .com * @param exportResource org.eclipse.core.resources.IResource * @param leadupDepth the number of resource levels to be included in the path including the resourse itself. */ public void exportResource(String rootName, String directory, String exportResource, int leadupDepth) throws InterruptedException { File file = new File(exportResource); if (file.isFile()) { String destinationName = file.getName(); if (!"".equals(directory)) { //$NON-NLS-1$ if (directory.endsWith(SEPARATOR)) { destinationName = directory + file.getName(); } else { destinationName = directory + SEPARATOR + file.getName(); } } if (createLeadupStructure) { if (rootName != null && !"".equals(destinationName)) { //$NON-NLS-1$ if (file.getName().equals("spagic.properties")) { //$NON-NLS-1$ destinationName = rootName.substring(0, rootName.indexOf("/")) + SEPARATOR //$NON-NLS-1$ + destinationName; } else if (!"".equals(rootName) && !rootName.equals(SEPARATOR)) { //$NON-NLS-1$ if (rootName.endsWith(SEPARATOR)) { destinationName = rootName + destinationName; } else { destinationName = rootName + SEPARATOR + destinationName; } } } } destinationName = destinationName.replace("//", SEPARATOR); //$NON-NLS-1$ monitor.subTask(destinationName); try { exporter.write(exportResource, destinationName); } catch (IOException e) { addError(NLS.bind("", exportResource, e.getMessage()), e); //$NON-NLS-1$ } catch (CoreException e) { addError(NLS.bind("", exportResource, e.getMessage()), e); //$NON-NLS-1$ } monitor.worked(1); ModalContext.checkCanceled(monitor); } else if (file.isDirectory()) { File[] children = null; try { children = file.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean result = true; if (pathname != null && pathname.isFile()) { try { result = Pattern.compile(regEx).matcher(pathname.getName()).find(); } catch (PatternSyntaxException e) { // here do nothing } } return result; } }); } catch (Exception e) { // this should never happen because an #isAccessible check is done before #members is invoked addError(NLS.bind("", exportResource), e); //$NON-NLS-1$ } for (File element : children) { exportResource(rootName, directory + file.getName() + SEPARATOR, element.getPath(), leadupDepth + 1); } } }