Example #1
0
 /**
  * Main entry point for Dart Model operations. Runs a Dart Model Operation as an
  * IWorkspaceRunnable if not read-only.
  */
 public void runOperation(IProgressMonitor monitor) throws DartModelException {
   DartModelStatus status = verify();
   if (!status.isOK()) {
     throw new DartModelException(status);
   }
   try {
     if (isReadOnly()) {
       run(monitor);
     } else {
       // Use IWorkspace.run(...) to ensure that resource changes are batched
       // Note that if the tree is locked, this will throw a CoreException, but
       // this is ok as this operation is modifying the tree (not read-only)
       // and a CoreException will be thrown anyway.
       ResourcesPlugin.getWorkspace()
           .run(this, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
     }
   } catch (CoreException ce) {
     if (ce instanceof DartModelException) {
       throw (DartModelException) ce;
     } else {
       if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
         Throwable e = ce.getStatus().getException();
         if (e instanceof DartModelException) {
           throw (DartModelException) e;
         }
       }
       throw new DartModelException(ce);
     }
   }
 }
Example #2
0
 /** Convenience method to run an operation within this operation. */
 public void executeNestedOperation(DartModelOperation operation, int subWorkAmount)
     throws DartModelException {
   DartModelStatus status = operation.verify();
   if (!status.isOK()) {
     throw new DartModelException(status);
   }
   IProgressMonitor subProgressMonitor = getSubProgressMonitor(subWorkAmount);
   // fix for 1FW7IKC, part (1)
   try {
     operation.setNested(true);
     operation.run(subProgressMonitor);
   } catch (CoreException ce) {
     if (ce instanceof DartModelException) {
       throw (DartModelException) ce;
     } else {
       // translate the core exception to a Dart model exception
       if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
         Throwable e = ce.getStatus().getException();
         if (e instanceof DartModelException) {
           throw (DartModelException) e;
         }
       }
       throw new DartModelException(ce);
     }
   }
 }