Search in sources :

Example 1 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project che by eclipse.

the class Workspace method delete.

@Override
public IStatus delete(IResource[] resources, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        int opWork = Math.max(resources.length, 1);
        int totalWork = Policy.totalWork * opWork / Policy.opWork;
        String message = Messages.resources_deleting_0;
        monitor.beginTask(message, totalWork);
        message = Messages.resources_deleteProblem;
        MultiStatus result = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INTERNAL_ERROR, message, null);
        if (resources.length == 0)
            return result;
        // to avoid concurrent changes to this array
        resources = resources.clone();
        try {
            prepareOperation(getRoot(), monitor);
            beginOperation(true);
            for (int i = 0; i < resources.length; i++) {
                Policy.checkCanceled(monitor);
                Resource resource = (Resource) resources[i];
                if (resource == null) {
                    monitor.worked(1);
                    continue;
                }
                try {
                    resource.delete(updateFlags, Policy.subMonitorFor(monitor, 1));
                } catch (CoreException e) {
                    // Don't really care about the exception unless the resource is still around.
                    ResourceInfo info = resource.getResourceInfo(false, false);
                    if (resource.exists(resource.getFlags(info), false)) {
                        message = NLS.bind(Messages.resources_couldnotDelete, resource.getFullPath());
                        result.merge(new org.eclipse.core.internal.resources.ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, resource.getFullPath(), message));
                        result.merge(e.getStatus());
                    }
                }
            }
            if (result.matches(IStatus.ERROR))
                throw new ResourceException(result);
            return result;
        } catch (OperationCanceledException e) {
            getWorkManager().operationCanceled();
            throw e;
        } finally {
            endOperation(getRoot(), true, Policy.subMonitorFor(monitor, totalWork - opWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) MultiStatus(org.eclipse.core.runtime.MultiStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 2 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project che by eclipse.

the class RefactoringHistoryManager method getCachedSession.

/**
	 * Returns the cached refactoring session descriptor.
	 *
	 * @param store
	 *            the file store of the descriptor
	 * @param projectName
	 *            project name, or <code>null</code> for the workspace
	 * @param input
	 *            the input stream where to read the descriptor
	 * @return the cached refactoring session descriptor
	 * @throws CoreException
	 *             if an error occurs while reading the session
	 */
private RefactoringSessionDescriptor getCachedSession(final IFileStore store, String projectName, final InputStream input) throws CoreException {
    if (store.equals(fCachedStore) && fCachedDescriptor != null)
        return fCachedDescriptor;
    final RefactoringSessionDescriptor descriptor;
    try {
        descriptor = new RefactoringSessionReader(false, projectName).readSession(new InputSource(input));
        fCachedDescriptor = descriptor;
        fCachedStore = store;
        return descriptor;
    } catch (CoreException e) {
        throw new CoreException(new MultiStatus(RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_IO_ERROR, new IStatus[] { e.getStatus() }, Messages.format(RefactoringCoreMessages.RefactoringHistoryManager_error_reading_file, BasicElementLabels.getURLPart(store.toURI().toString())), null));
    }
}
Also used : InputSource(org.xml.sax.InputSource) RefactoringSessionReader(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)

Example 3 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project cubrid-manager by CUBRID.

the class ImportDataFromFileDialog method finish.

/**
	 *
	 * After task finished, call it
	 *
	 *
	 *
	 */
private void finish() {
    if (getStartShowResult()) {
        return;
    } else {
        setStartShowResult(true);
    }
    if (importFileHandler instanceof XLSImportFileHandler) {
        XLSImportFileHandler xlsHandler = (XLSImportFileHandler) importFileHandler;
        xlsHandler.dispose();
    } else if (importFileHandler instanceof XLSXImportFileHandler) {
        XLSXImportFileHandler xlsHandler = (XLSXImportFileHandler) importFileHandler;
        xlsHandler.dispose();
    }
    long endTimestamp = System.currentTimeMillis();
    String spendTime = calcSpendTime(beginTimestamp, endTimestamp);
    List<Status> allStatusList = new ArrayList<Status>();
    int commitedCount = 0;
    boolean isHasError = false;
    boolean isCancel = false;
    List<String> errorList = new ArrayList<String>();
    int totalErrorCount = 0;
    for (PstmtDataTask task : taskList) {
        commitedCount += task.getCommitedCount();
        isCancel = isCancel || task.isCancel();
        if (!task.isSuccess() && task.getErrorMsg() != null) {
            Status status = new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, task.getErrorMsg());
            allStatusList.add(status);
            isHasError = true;
        }
        errorList.addAll(task.getErrorMsgList());
        totalErrorCount = totalErrorCount + task.getTotalErrorCount();
        if (!errorList.isEmpty()) {
            isHasError = true;
        }
    }
    if (!isHasError && isCancel) {
        String msg = Messages.bind(Messages.msgCancelExecSql, new String[] { String.valueOf(commitedCount), spendTime });
        CommonUITool.openInformationBox(getShell(), Messages.titleExecuteResult, msg);
        close();
        deleteLog();
        return;
    }
    String successMsg = Messages.bind(Messages.msgSuccessExecSql, new String[] { String.valueOf(commitedCount), spendTime });
    if (!isHasError) {
        CommonUITool.openInformationBox(getShell(), Messages.titleExecuteResult, successMsg);
        close();
        deleteLog();
        return;
    }
    if (errorList.isEmpty()) {
        // break
        Status status = new Status(IStatus.INFO, CommonUIPlugin.PLUGIN_ID, successMsg + "\r\n");
        allStatusList.add(0, status);
        IStatus[] errors = new IStatus[allStatusList.size()];
        allStatusList.toArray(errors);
        MultiStatus multiStatus = new MultiStatus(CommonUIPlugin.PLUGIN_ID, IStatus.OK, errors, Messages.msgDetailCause, null);
        String errorMsg = Messages.bind(Messages.errExecSql, new String[] { String.valueOf(commitedCount), spendTime });
        ErrorDialog errorDialog = new ErrorDialog(getShell(), Messages.titleExecuteResult, errorMsg, multiStatus, IStatus.INFO | IStatus.ERROR);
        errorDialog.open();
        if (isHasError) {
            getShell().setVisible(true);
        } else {
            close();
        }
    } else {
        //ignore the error
        String msg = Messages.bind(Messages.importColumnNOTotal, String.valueOf(totalErrorCount)) + "\r\n" + successMsg;
        ImportResultDialog dialog = new ImportResultDialog(getShell(), msg, errorList, errorLogDir);
        dialog.open();
        close();
    }
    deleteLog();
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) XLSXImportFileHandler(com.cubrid.common.ui.cubrid.table.importhandler.handler.XLSXImportFileHandler) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) XLSImportFileHandler(com.cubrid.common.ui.cubrid.table.importhandler.handler.XLSImportFileHandler)

Example 4 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project translationstudio8 by heartsome.

the class OpenMessageUtils method throwable2MultiStatus.

/**
	 * 将<code>Throwable<code>转化成<code>MultiStatus<code>对象,
	 * 让<code>MultiStatus<code>对象包含详细的<code>Throwable<code>详细的堆栈信息。
	 * @param message
	 *            <code>MultiStatus<code>对象的消息
	 * @param throwable
	 *            异常对象
	 * @return 包含有详细的堆栈信息的<code>MultiStatus<code>对象;
	 */
public static MultiStatus throwable2MultiStatus(String message, Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    throwable.printStackTrace(pw);
    // stack trace as a string
    final String trace = sw.toString();
    // Temp holder of child statuses
    List<Status> childStatuses = new ArrayList<Status>();
    // Split output by OS-independend new-line
    //$NON-NLS-N$
    String[] lines = trace.split(System.getProperty("line.separator"));
    int j = lines.length == 1 ? 0 : 1;
    for (int i = j; i < lines.length; i++) {
        String line = lines[i];
        // build & add status
        childStatuses.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, line));
    }
    // convert to array of statuses
    MultiStatus ms = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, childStatuses.toArray(new Status[] {}), message, throwable);
    return ms;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) PrintWriter(java.io.PrintWriter)

Example 5 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project translationstudio8 by heartsome.

the class ResourceDropAdapterAssistant method performResourceCopy.

/**
	 * Performs a resource copy
	 */
private IStatus performResourceCopy(CommonDropAdapter dropAdapter, Shell shell, IResource[] sources) {
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null);
    mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation()));
    IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());
    boolean shouldLinkAutomatically = false;
    if (target.isVirtual()) {
        shouldLinkAutomatically = true;
        for (int i = 0; i < sources.length; i++) {
            if ((sources[i].getType() != IResource.FILE) && (sources[i].getLocation() != null)) {
                // If the source is a folder, but the location is null (a
                // broken link, for example),
                // we still generate a link automatically (the best option).
                shouldLinkAutomatically = false;
                break;
            }
        }
    }
    CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
    // automatically create links
    if (shouldLinkAutomatically) {
        operation.setCreateLinks(true);
        operation.copyResources(sources, target);
    } else {
        //			boolean allSourceAreLinksOrVirtualFolders = true;
        //			for (int i = 0; i < sources.length; i++) {
        //				if (!sources[i].isVirtual() && !sources[i].isLinked()) {
        //					allSourceAreLinksOrVirtualFolders = false;
        //					break;
        //				}
        //			}
        //			// if all sources are either links or groups, copy then normally,
        //			// don't show the dialog
        //			if (!allSourceAreLinksOrVirtualFolders) {
        //				IPreferenceStore store= IDEWorkbenchPlugin.getDefault().getPreferenceStore();
        //				String dndPreference= store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
        //
        //				if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
        //					ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target);
        //					dialog.setResource(target);
        //					if (dialog.open() == Window.OK) {
        //						if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
        //							operation.setVirtualFolders(true);
        //						if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
        //							operation.setCreateLinks(true);
        //						if (dialog.getVariable() != null)
        //							operation.setRelativeVariable(dialog.getVariable());
        //						operation.copyResources(sources, target);
        //					} else
        //						return problems;
        //				}
        //				else
        //					operation.copyResources(sources, target);
        //			} else
        operation.copyResources(sources, target);
    }
    return problems;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IContainer(org.eclipse.core.resources.IContainer) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation)

Aggregations

MultiStatus (org.eclipse.core.runtime.MultiStatus)146 IStatus (org.eclipse.core.runtime.IStatus)102 Status (org.eclipse.core.runtime.Status)62 CoreException (org.eclipse.core.runtime.CoreException)41 ArrayList (java.util.ArrayList)29 File (java.io.File)24 SubMonitor (org.eclipse.core.runtime.SubMonitor)24 IOException (java.io.IOException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 List (java.util.List)11 HashMap (java.util.HashMap)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)10 IPath (org.eclipse.core.runtime.IPath)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 FileNotFoundException (java.io.FileNotFoundException)7 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 IContainer (org.eclipse.core.resources.IContainer)6 URI (java.net.URI)5