Search in sources :

Example 31 with IStatus

use of org.eclipse.core.runtime.IStatus in project generator by mybatis.

the class RunGeneratorAction method handleException.

private void handleException(Exception exception, Shell shell) {
    IStatus status;
    Throwable exceptionToHandle;
    if (exception instanceof InvocationTargetException) {
        exceptionToHandle = ((InvocationTargetException) exception).getCause();
    } else {
        exceptionToHandle = exception;
    }
    if (exceptionToHandle instanceof InterruptedException) {
        status = new Status(IStatus.CANCEL, Activator.PLUGIN_ID, IStatus.CANCEL, "Cancelled by User", exceptionToHandle);
    } else if (exceptionToHandle instanceof CoreException) {
        status = ((CoreException) exceptionToHandle).getStatus();
    } else {
        String message = "Unexpected error while running MyBatis Generator.";
        status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, message, exceptionToHandle);
        Activator.getDefault().getLog().log(status);
    }
    ErrorDialog.openError(shell, "MyBatis Generator", "Generation Failed", status, IStatus.ERROR | IStatus.CANCEL);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with IStatus

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

the class Resources method makeCommittable.

/**
	 * Makes the given resources committable. Committable means that all
	 * resources are writeable and that the content of the resources hasn't
	 * changed by calling <code>validateEdit</code> for a given file on
	 * <tt>IWorkspace</tt>.
	 *
	 * @param resources the resources to be checked
	 * @param context the context passed to <code>validateEdit</code>
	 * @return IStatus status describing the method's result. If <code>status.
	 * isOK()</code> returns <code>true</code> then the add resources are
	 * committable
	 *
	 * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], Object)
	 */
public static IStatus makeCommittable(IResource[] resources, Object context) {
    List<IResource> readOnlyFiles = new ArrayList<IResource>();
    for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        if (resource.getType() == IResource.FILE && isReadOnly(resource))
            readOnlyFiles.add(resource);
    }
    if (readOnlyFiles.size() == 0)
        return Status.OK_STATUS;
    Map<IFile, Long> oldTimeStamps = createModificationStampMap(readOnlyFiles);
    IStatus status = ResourcesPlugin.getWorkspace().validateEdit(readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]), context);
    if (!status.isOK())
        return status;
    IStatus modified = null;
    Map<IFile, Long> newTimeStamps = createModificationStampMap(readOnlyFiles);
    for (Iterator<IFile> iter = oldTimeStamps.keySet().iterator(); iter.hasNext(); ) {
        IFile file = iter.next();
        if (!oldTimeStamps.get(file).equals(newTimeStamps.get(file)))
            modified = addModified(modified, file);
    }
    if (modified != null)
        return modified;
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JavaUIStatus(org.eclipse.jdt.internal.ui.JavaUIStatus) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource)

Example 33 with IStatus

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

the class Resources method makeCommittable.

/**
	 * Makes the given resources committable. Committable means that all
	 * resources are writeable and that the content of the resources hasn't
	 * changed by calling <code>validateEdit</code> for a given file on
	 * <tt>IWorkspace</tt>.
	 *
	 * @param resources the resources to be checked
	 * @param context the context passed to <code>validateEdit</code>
	 * @return IStatus status describing the method's result. If <code>status.
	 * isOK()</code> returns <code>true</code> then the add resources are
	 * committable
	 *
	 * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
	 */
public static IStatus makeCommittable(IResource[] resources, Object context) {
    List readOnlyFiles = new ArrayList();
    for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        if (resource.getType() == IResource.FILE && isReadOnly(resource))
            readOnlyFiles.add(resource);
    }
    if (readOnlyFiles.size() == 0)
        return Status.OK_STATUS;
    Map oldTimeStamps = createModificationStampMap(readOnlyFiles);
    IStatus status = ResourcesPlugin.getWorkspace().validateEdit((IFile[]) readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]), context);
    if (!status.isOK())
        return status;
    IStatus modified = null;
    Map newTimeStamps = createModificationStampMap(readOnlyFiles);
    for (Iterator iter = oldTimeStamps.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Entry) iter.next();
        if (!entry.getValue().equals(newTimeStamps.get(entry.getKey())))
            modified = addModified(modified, (IFile) entry.getKey());
    }
    if (modified != null)
        return modified;
    return Status.OK_STATUS;
}
Also used : Entry(java.util.Map.Entry) IStatus(org.eclipse.core.runtime.IStatus) Entry(java.util.Map.Entry) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 34 with IStatus

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

the class ResourceChangeChecker method createFrom.

private static RefactoringStatus createFrom(IStatus status) {
    if (status.isOK())
        return new RefactoringStatus();
    if (!status.isMultiStatus()) {
        switch(status.getSeverity()) {
            case IStatus.OK:
                return new RefactoringStatus();
            case IStatus.INFO:
                return RefactoringStatus.createInfoStatus(status.getMessage());
            case IStatus.WARNING:
                return RefactoringStatus.createWarningStatus(status.getMessage());
            case IStatus.ERROR:
                return RefactoringStatus.createErrorStatus(status.getMessage());
            case IStatus.CANCEL:
                return RefactoringStatus.createFatalErrorStatus(status.getMessage());
            default:
                return RefactoringStatus.createFatalErrorStatus(status.getMessage());
        }
    } else {
        IStatus[] children = status.getChildren();
        RefactoringStatus result = new RefactoringStatus();
        for (int i = 0; i < children.length; i++) {
            result.merge(createFrom(children[i]));
        }
        return result;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 35 with IStatus

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

the class ValidateEditChecker method check.

/**
	 * {@inheritDoc}
	 */
public RefactoringStatus check(IProgressMonitor monitor) throws CoreException {
    IResource[] resources = (IResource[]) fFiles.toArray(new IResource[fFiles.size()]);
    RefactoringStatus result = new RefactoringStatus();
    IStatus status = Resources.checkInSync(resources);
    if (!status.isOK())
        result.merge(RefactoringStatus.create(status));
    status = Resources.makeCommittable(resources, fContext);
    if (!status.isOK()) {
        result.merge(RefactoringStatus.create(status));
        if (!result.hasFatalError()) {
            result.addFatalError(RefactoringCoreMessages.ValidateEditChecker_failed);
        }
    }
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResource(org.eclipse.core.resources.IResource)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)417 Status (org.eclipse.core.runtime.Status)195 CoreException (org.eclipse.core.runtime.CoreException)103 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)81 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)46 File (java.io.File)40 InvocationTargetException (java.lang.reflect.InvocationTargetException)39 ITask (com.cubrid.common.core.task.ITask)37 Job (org.eclipse.core.runtime.jobs.Job)32 IFile (org.eclipse.core.resources.IFile)31 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)29 IPath (org.eclipse.core.runtime.IPath)29 List (java.util.List)23 IResource (org.eclipse.core.resources.IResource)22 MultiStatus (org.eclipse.core.runtime.MultiStatus)22 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)19 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)18 InputStream (java.io.InputStream)17