Example #1
0
  /**
   * Schedules a message dialog to be displayed safely in the UI thread
   *
   * @param runnable Something that gets run if the message dialog return code is Window.OK
   * @param runnableCondition The return code from SafeMessageDialogRunnable.openMessageDialog()
   *     that would trigger SafeMessageDialogRunnable.run()
   */
  public static void showMessageDialogFromBgThread(
      final SafeMessageDialogRunnable runnable, final int runnableCondition) {
    UIJob job = new UIJob("Modal Message Dialog Job") // $NON-NLS-1$
        {

          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            // If the system dialog is shown, then the active shell would be null
            if (Display.getDefault().getActiveShell() == null) {
              if (!monitor.isCanceled()) {
                schedule(1000);
              }
            } else if (!monitor.isCanceled()) {
              if (runnable.openMessageDialog() == runnableCondition) {
                try {
                  runnable.run();
                } catch (Exception e) {
                  IdeLog.logError(UIPlugin.getDefault(), e);
                }
              }
            }
            return Status.OK_STATUS;
          }
        };
    EclipseUtil.setSystemForJob(job);
    job.schedule();
  }
 /**
  * Displays a yes/no dialog of a specified type with a specified title,a specified message, and a
  * specified default value, then blocks until the user responds or interrupts the dialog.
  *
  * @param type the dialog type, specified by one of the int constants in {@link MessageDialog}
  * @param title the specified title
  * @param message the specified message
  * @param defaultIsYes {@link true} if the specified default value is <i>yes</i>, false if the
  *     specified default value is <i>no</i>
  * @return {@code true} if the user responded <i>yes</i>, {@code false} if the user responded
  *     <i>no</i>, or the value of {@code defaultValueIsYes} if the user interrupts the dialog
  */
 public boolean userAnsweredYes(
     final int type, final String title, final String message, final boolean defaultIsYes) {
   final int defaultPosition = defaultIsYes ? YesOrNo.YES.ordinal() : YesOrNo.NO.ordinal();
   if (Display.getCurrent() == null) {
     // This is not a UI thread. Schedule a UI job to call displayDialogAndGetAnswer, and block
     // this thread until the UI job is complete.
     final Semaphore barrier = new Semaphore(0);
     final AtomicBoolean responseContainer = new AtomicBoolean();
     UIJob dialogJob =
         new UIJob("background-initiated question dialog") {
           @Override
           public IStatus runInUIThread(IProgressMonitor monitor) {
             boolean result = displayDialogAndGetAnswer(type, title, message, defaultPosition);
             responseContainer.set(result);
             barrier.release();
             return Status.OK_STATUS;
           }
         };
     dialogJob.schedule();
     try {
       barrier.acquire();
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       return defaultIsYes;
     }
     return responseContainer.get();
   } else {
     // This is the UI thread. Simply call displayDialogAndGetAnswer in this thread.
     // (Scheduling a UIJob and blocking until it completes would result in deadlock.)
     return displayDialogAndGetAnswer(type, title, message, defaultPosition);
   }
 }
 public void playPorts(final List<ScaUsesPort> portList) {
   final UIJob job =
       new UIJob("Starting Play Port") {
         @Override
         public IStatus runInUIThread(final IProgressMonitor monitor) {
           monitor.beginTask("Opening Play Port View", IProgressMonitor.UNKNOWN);
           final IWorkbenchPage page =
               PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
           if (page != null) {
             PlayAudioView view;
             try {
               view = (PlayAudioView) page.showView(PlayAudioView.ID);
               for (ScaUsesPort port : portList) {
                 view.playPort(port);
               }
               PortHelper.refreshPorts(portList, monitor);
             } catch (final PartInitException e) {
               getLog()
                   .log(
                       new Status(
                           IStatus.ERROR, Activator.PLUGIN_ID, "Error finding Play Port View", e));
             }
           }
           return Status.OK_STATUS;
         }
       };
   job.setSystem(true);
   job.schedule();
 }
  private boolean attemptResizeColumnsToPreferredSize() {
    if (fPendingResizeColumns) {
      if (!hasPendingUpdates()) {
        UIJob job = new UIJob("packcolumns") { // $NON-NLS-1$

              public IStatus runInUIThread(IProgressMonitor monitor) {
                Table table = getTable();

                if (!table.isDisposed()) {
                  // if table size is zero, the rendering has not been made visible
                  // cannot pack until the rendering is visible
                  if (table.getSize().x > 0) {
                    TableColumn[] columns = table.getColumns();
                    for (int i = 0; i < columns.length - 1; i++) {
                      columns[i].pack();
                    }
                  } else {
                    fPendingResizeColumns = true;
                  }
                }
                return Status.OK_STATUS;
              }
            };
        job.setSystem(true);
        job.schedule();
        return false;
      }
    }
    return fPendingResizeColumns;
  }
Example #5
0
 /**
  * Adds the scheduled job to the list of running jobs and gives the user optical feedback that the
  * requested node is being calculated.
  */
 @Override
 public void scheduled(final IJobChangeEvent event) {
   UIJob refreshJob =
       new UIJob(REFRESH_STATISTICS_VIEW) {
         @Override
         public IStatus runInUIThread(IProgressMonitor monitor) {
           Job job = event.getJob();
           if (job instanceof ITreeJob) {
             final LongRunningJob<?> treeJob = (LongRunningJob<?>) job;
             runningJobs.add(treeJob);
             Parent calc = ((TreeJob) treeJob.getMethod()).getCalculated();
             calc.startCalculating(true);
             checkViews();
             synchronized (views) {
               for (TreeViewer view : views) {
                 view.refresh(calc);
               }
             }
           }
           return Status.OK_STATUS;
         }
       };
   refreshJob.setPriority(Job.INTERACTIVE);
   refreshJob.schedule();
 }
Example #6
0
 /** Reverses the actions of {@link JobDoneListener#scheduled(IJobChangeEvent)} */
 @Override
 public void done(final IJobChangeEvent event) {
   if (event.getResult() == Status.OK_STATUS || event.getResult() == Status.CANCEL_STATUS) {
     UIJob refreshJob =
         new UIJob(REFRESH_STATISTICS_VIEW) {
           @Override
           public IStatus runInUIThread(IProgressMonitor monitor) {
             Job job = event.getJob();
             if (job instanceof ITreeJob) {
               final LongRunningJob<?> treeJob = (LongRunningJob<?>) job;
               LongRunningMethod<?> method = treeJob.getMethod();
               final boolean expand =
                   (method instanceof StatisticTreeJob) && ((StatisticTreeJob) method).isExpand();
               runningJobs.remove(treeJob);
               final Parent calc = ((TreeJob) method).getCalculated();
               calc.startCalculating(false);
               checkViews();
               synchronized (views) {
                 for (TreeViewer view : views) {
                   view.refresh(calc);
                   if (expand) {
                     view.expandToLevel(calc, 1);
                   }
                 }
               }
             }
             return Status.OK_STATUS;
           }
         };
     refreshJob.setPriority(Job.INTERACTIVE);
     refreshJob.schedule();
   }
 }
 public void hookOnViewer(final String viewerId) {
   IWorkbench workbench = PlatformUI.getWorkbench();
   if (viewerId != null && workbench != null && workbench.getDisplay() != null) {
     Display display = workbench.getDisplay();
     Thread displayThread = display.getThread();
     if (workbench.isStarting() || !Thread.currentThread().equals(displayThread)) {
       // while workbench is starting defer hooking until later
       UIJob job =
           new UIJob(display, "viewer hooker") {
             @Override
             public IStatus runInUIThread(IProgressMonitor monitor) {
               hookOnViewer(viewerId);
               return Status.OK_STATUS;
             }
           };
       job.schedule(250);
     } else if (viewerId != null) {
       CommonNavigator navigator =
           (CommonNavigator) eu.fittest.eclipse.gui.utils.Viewer.getView(viewerId);
       if (navigator != null) {
         CommonViewer viewer = navigator.getCommonViewer();
         if (viewer != null) {
           if (this.viewer != null) {
             this.viewer.removeSelectionChangedListener(this);
           }
           requestRefresh();
           viewer.addSelectionChangedListener(this);
           this.viewer = viewer;
         }
       }
     }
   }
 }
  @Override
  public void componentChanged(final ITraceControlComponent component) {
    if (fTreeViewer.getTree().isDisposed()) {
      return;
    }

    UIJob myJob = new UIJob("Refresh") { // $NON-NLS-1$
          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            if (fTreeViewer.getTree().isDisposed()) {
              return Status.OK_STATUS;
            }

            fTreeViewer.refresh(component);

            // Change selection needed
            final ISelection sel = fTreeViewer.getSelection();
            fTreeViewer.setSelection(null);
            fTreeViewer.setSelection(sel);

            // Show component that was changed
            fTreeViewer.reveal(component);

            return Status.OK_STATUS;
          }
        };
    myJob.setUser(false);
    myJob.setSystem(true);
    myJob.schedule();
  }
 @Override
 public boolean prepareDecoration(Object element, String originalText) {
   final IFile f = (IFile) element;
   if (isImageFile(f)) {
     if (images.containsKey(f)) {
       return true;
     } else {
       final Display d = Display.getDefault();
       UIJob prepareImage =
           new UIJob(d, "prepare Image") {
             @Override
             public IStatus runInUIThread(IProgressMonitor monitor) {
               try {
                 images.put(f, prepareImage(d, f));
                 LabelProviderChangedEvent event =
                     new LabelProviderChangedEvent(ImagePreviewDecorator.this, f);
                 for (ILabelProviderListener x : listeners) {
                   x.labelProviderChanged(event);
                 }
                 return Status.OK_STATUS;
               } catch (CoreException e) {
                 return new Status(
                     IStatus.ERROR, Activator.PLUGIN_ID, "failed to load image preview", e);
               }
             }
           };
       prepareImage.setPriority(Job.DECORATE);
       prepareImage.schedule();
     }
     return false;
   }
   return true;
 }
 /**
  * Sets the selected components in the tree
  *
  * @param components - array of components to select
  */
 public void setSelection(ITraceControlComponent[] components) {
   final StructuredSelection selection = new StructuredSelection(components);
   UIJob myJob = new UIJob("Select") { // $NON-NLS-1$
         @Override
         public IStatus runInUIThread(IProgressMonitor monitor) {
           fTreeViewer.setSelection(selection);
           return Status.OK_STATUS;
         }
       };
   myJob.setUser(false);
   myJob.schedule();
 }
Example #11
0
  public void onRefsChanged(RefsChangedEvent event) {
    if (getCommit().getRepository().getDirectory().equals(event.getRepository().getDirectory())) {
      UIJob job = new UIJob("Refreshing editor") { // $NON-NLS-1$

            public IStatus runInUIThread(IProgressMonitor monitor) {
              if (!getContainer().isDisposed()) commitPage.refresh();
              return Status.OK_STATUS;
            }
          };
      job.schedule();
    }
  }
Example #12
0
    @Override
    public void run() {
      try {

        UIJob j =
            new UIJob(getToolTipText()) {

              @Override
              public IStatus runInUIThread(IProgressMonitor monitor) {
                try {
                  PrologConsole c = getConsole();
                  int caretOffset = c.getCaretOffset();
                  int offsetInLineBuffer = caretOffset - c.getStartOfInput();
                  ConsoleModel model = c.getModel();
                  String lineBuffer = model.getLineBuffer();
                  if (offsetInLineBuffer < 0) {
                    offsetInLineBuffer = lineBuffer.length();
                    caretOffset = c.getStartOfInput() + lineBuffer.length();
                  }

                  String textToInsert = getTextToInsert();
                  if (textToInsert == null) {
                    return Status.OK_STATUS;
                  }
                  lineBuffer =
                      lineBuffer.substring(0, offsetInLineBuffer)
                          + textToInsert
                          + lineBuffer.substring(offsetInLineBuffer);

                  model.setLineBuffer(lineBuffer);
                  c.setCaretOffset(caretOffset + textToInsert.length());

                } catch (Throwable e) {
                  Debug.report(e);
                  return Status.CANCEL_STATUS;
                } finally {
                  monitor.done();
                }
                return Status.OK_STATUS;
              }

              private PrologConsole getConsole() {
                return PrologConsoleView.this;
              }
            };

        j.schedule();
      } catch (Throwable t) {
        Debug.report(t);
      }
    }
    /** As soon as the reparse is done, this method is called to actually make the rename. */
    public void parserChanged(ISimpleNode root, IAdaptable file, IDocument doc) {
      pyEdit.getParser().removeParseListener(this); // we'll only listen for this single parse

      /**
       * Create an ui job to actually make the rename (otherwise we can't make ui.enter() nor create
       * a PySelection.)
       */
      UIJob job =
          new UIJob("Rename") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
              try {
                ISourceViewer viewer = pyEdit.getPySourceViewer();
                IDocument document = viewer.getDocument();
                PySelection ps = new PySelection(pyEdit);
                LinkedPositionGroup group = new LinkedPositionGroup();

                if (!fillWithOccurrences(document, group, new NullProgressMonitor(), ps)) {
                  return Status.OK_STATUS;
                }

                if (group.isEmpty()) {
                  return Status.OK_STATUS;
                }

                LinkedModeModel model = new LinkedModeModel();
                model.addGroup(group);
                if (model.tryInstall() && model.getTabStopSequence().size() > 0) {
                  final LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
                  Tuple<String, Integer> currToken = ps.getCurrToken();
                  ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS);
                  ui.setExitPosition(
                      viewer,
                      currToken.o2 + currToken.o1.length(),
                      0,
                      0 /*ordered so that 0 is current pos*/);
                  ui.enter();
                }
              } catch (BadLocationException e) {
                Log.log(e);
              } catch (Throwable e) {
                Log.log(e);
              }
              return Status.OK_STATUS;
            }
          };
      job.setPriority(Job.INTERACTIVE);
      job.schedule();
    }
Example #14
0
  public void fireMonitorUpdated(final IMonitorControl[] monitors) {
    UIJob job =
        new UIJob(Messages.MonitorControlManager_monitorUpdatedJobName) {

          @Override
          public IStatus runInUIThread(IProgressMonitor progress) {
            for (Object listener : fMonitorChangedListeners.getListeners()) {
              ((IMonitorChangedListener) listener).monitorUpdated(monitors);
            }
            return Status.OK_STATUS;
          }
        };
    job.schedule();
  }
 /**
  * Remove all the temporary annotations added by this validator to the the active not dirty
  * editor.
  */
 static void removeMessages() {
   UIJob job =
       new UIJob("Removing as-you-type JBT validation problems") {
         public IStatus runInUIThread(IProgressMonitor monitor) {
           if (!EclipseUIUtil.isActiveEditorDirty()) {
             ITextEditor e = EclipseUIUtil.getActiveEditor();
             if (e != null) {
               IEditorInput input = e.getEditorInput();
               IDocumentProvider dp = e.getDocumentProvider();
               IDocument doc = dp.getDocument(input);
               boolean ok = false;
               synchronized (reporters) {
                 ok = reporters.contains(doc);
               }
               if (ok) {
                 IAnnotationModel model = dp.getAnnotationModel(input);
                 if (model instanceof AbstractMarkerAnnotationModel) {
                   AbstractMarkerAnnotationModel anModel = ((AbstractMarkerAnnotationModel) model);
                   synchronized (anModel.getLockObject()) {
                     Iterator iterator = anModel.getAnnotationIterator();
                     while (iterator.hasNext()) {
                       Object o = iterator.next();
                       if (o instanceof TemporaryAnnotation) {
                         TemporaryAnnotation annotation = (TemporaryAnnotation) o;
                         Map attributes = annotation.getAttributes();
                         if (attributes != null
                             && attributes.get(
                                     TempMarkerManager.AS_YOU_TYPE_VALIDATION_ANNOTATION_ATTRIBUTE)
                                 != null) {
                           anModel.removeAnnotation(annotation);
                         }
                       } else if (o instanceof DisabledAnnotation) {
                         DisabledAnnotation annotation = (DisabledAnnotation) o;
                         anModel.removeAnnotation(annotation);
                       } else if (o instanceof TempJavaProblemAnnotation) {
                         TempJavaProblemAnnotation annotation = (TempJavaProblemAnnotation) o;
                         anModel.removeAnnotation(annotation);
                       }
                     }
                   }
                 }
               }
             }
           }
           return Status.OK_STATUS;
         }
       };
   job.schedule();
 }
 private void resetName() {
   final String newName = computeName();
   final String name = getName();
   if (!name.equals(newName)) {
     final UIJob job = new UIJob("Update console title") { // $NON-NLS-1$
           @Override
           public IStatus runInUIThread(final IProgressMonitor monitor) {
             KarafRemoteConsole.this.setName(newName);
             return Status.OK_STATUS;
           }
         };
     job.setSystem(true);
     job.schedule();
   }
 }
 private void postAsyncUpdate(final Display display) {
   if (fUpdateJob == null) {
     fUpdateJob =
         new UIJob(display, "Update Script explorer") { // $NON-NLS-1$
           public IStatus runInUIThread(IProgressMonitor monitor) {
             TreeViewer viewer = fViewer;
             if (viewer != null && viewer.isBusy()) {
               // reschedule when viewer is busy: bug 184991
               schedule(100);
             } else {
               runPendingUpdates();
             }
             return Status.OK_STATUS;
           }
         };
     fUpdateJob.setSystem(true);
   }
   fUpdateJob.schedule();
 }
Example #18
0
  /** @see com.aptana.ide.editors.unified.ContributedBrowser#displaySource() */
  public void displaySource() {
    if (document != null) {
      nsIDOMSerializer serializer =
          (nsIDOMSerializer)
              Mozilla.getInstance()
                  .getComponentManager()
                  .createInstanceByContractID(
                      "@mozilla.org/xmlextras/xmlserializer;1",
                      null, //$NON-NLS-1$
                      nsIDOMSerializer.NS_IDOMSERIALIZER_IID);
      String source = serializer.serializeToString(document.getDocumentElement());
      try {
        final String newFileName =
            FileUtils.getRandomFileName("source", ".html"); // $NON-NLS-1$ //$NON-NLS-2$
        final File temp = new File(FileUtils.systemTempDir + File.separator + newFileName);
        FileUtils.writeStringToFile(source, temp);
        UIJob openJob =
            new UIJob(Messages.getString("FirefoxBrowser.Open_Source_Editor")) // $NON-NLS-1$
            {

              public IStatus runInUIThread(IProgressMonitor monitor) {
                IEditorInput input = CoreUIUtils.createJavaFileEditorInput(temp);
                try {
                  IDE.openEditor(
                      Activator.getDefault()
                          .getWorkbench()
                          .getActiveWorkbenchWindow()
                          .getActivePage(),
                      input,
                      IDE.getEditorDescriptor(newFileName).getId());
                } catch (PartInitException e) {
                  e.printStackTrace();
                }
                return Status.OK_STATUS;
              }
            };
        openJob.schedule();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Example #19
0
 private static void showErrorMessage(
     final String title, final String message, final Throwable exception) {
   if (Display.getCurrent() == null || exception != null) {
     UIJob job =
         new UIJob(message) {
           @Override
           public IStatus runInUIThread(IProgressMonitor monitor) {
             if (exception == null) {
               showErrorDialog(title, message);
               return Status.OK_STATUS;
             }
             return new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID, null, exception);
           }
         };
     job.setPriority(Job.INTERACTIVE);
     job.setUser(true);
     job.schedule();
   } else {
     showErrorDialog(title, message);
   }
 }
Example #20
0
  public void fireSelectionChanged(final SelectionChangedEvent event) {
    UIJob job =
        new UIJob(Messages.MonitorControlManager_monitorSelectionChangedJobName) {

          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            for (Object listener : fSelectionChangedListeners.getListeners()) {
              ((ISelectionChangedListener) listener).selectionChanged(event);
            }
            String monitorId = null;
            if (event.getSelection() instanceof IStructuredSelection) {
              IStructuredSelection sel = (IStructuredSelection) event.getSelection();
              if (!sel.isEmpty()) {
                monitorId = ((IMonitorControl) sel.getFirstElement()).getId();
              }
            }
            LMLManager.getInstance().selectLgui(monitorId);
            return Status.OK_STATUS;
          }
        };
    job.schedule();
  }
Example #21
0
 public static boolean showPromptDialog(final String title, final String message) {
   if (Display.getCurrent() == null) {
     UIJob job =
         new UIJob(title) {
           @Override
           public IStatus runInUIThread(IProgressMonitor monitor) {
             if (showPromptDialogUI(title, message)) {
               return Status.OK_STATUS;
             }
             return Status.CANCEL_STATUS;
           }
         };
     job.setPriority(Job.INTERACTIVE);
     job.setUser(true);
     job.schedule();
     try {
       job.join();
     } catch (InterruptedException e) {
     }
     return job.getResult() == Status.OK_STATUS;
   } else {
     return showPromptDialogUI(title, message);
   }
 }
Example #22
0
  private void setGrammarEditor(IWorkbenchPart activeEditor) {
    if (featureModelEditor == activeEditor) return;

    if (featureModelEditor != null) {
      featureModelEditor.getOriginalFeatureModel().removeListener(modelListener);
      featureModelEditor.getFeatureModel().removeListener(modelListener);
      featureModelEditor = null;
    }

    if (activeEditor instanceof FeatureModelEditor) {
      featureModelEditor = (FeatureModelEditor) activeEditor;
      featureModelEditor.getOriginalFeatureModel().addListener(modelListener);
      featureModelEditor.getFeatureModel().addListener(modelListener);

      if (evaluation == null
          && featureModelEditor != null
          && featureModelEditor
              .getGrammarFile()
              .getResource()
              .getProject()
              .getName()
              .startsWith("EvaluationTest")) {
        evaluation =
            new Job("Evaluation Test") {
              @Override
              protected IStatus run(IProgressMonitor monitor) {
                Evaluation.evaluate(featureModelEditor.getGrammarFile().getResource().getProject());
                return Status.OK_STATUS;
              }
            };
        evaluation.setPriority(Job.LONG);
        evaluation.schedule();
        UIJob conversion =
            new UIJob("Converting Feature Models") {
              @Override
              public IStatus runInUIThread(IProgressMonitor monitor) {
                try {
                  convertModelToBitmapTest(
                      featureModelEditor
                          .getGrammarFile()
                          .getResource()
                          .getProject()
                          .getFolder("models"));
                } catch (Exception e) {
                  e.printStackTrace();
                }
                return Status.OK_STATUS;
              }

              public void convertModelToBitmapTest(IFolder folder) throws CoreException {
                for (IResource res : folder.members())
                  if (res instanceof IFile && res.getName().endsWith(".m")) {
                    IFile fmFile = (IFile) res;
                    try {
                      FeatureModel fm = new FeatureModel();
                      FeatureModelReader reader = new FeatureModelReader(fm);
                      reader.readFromFile(fmFile);

                      String imageName = fmFile.getRawLocation().toOSString();
                      imageName =
                          imageName.substring(0, imageName.length() - ".m".length()) + ".png";
                      createBitmap(fm, new File(imageName));
                    } catch (FileNotFoundException e) {
                      e.printStackTrace();
                    } catch (UnsupportedModelException e) {
                      e.printStackTrace();
                    }
                  }
                folder.refreshLocal(IResource.DEPTH_ONE, null);
              }

              private void createBitmap(FeatureModel featureModel, File file) {
                GraphicalViewerImpl graphicalViewer = new ScrollingGraphicalViewer();
                graphicalViewer.createControl(viewer.getControl().getParent());
                graphicalViewer.getControl().setBackground(GUIDefaults.DIAGRAM_BACKGROUND);
                graphicalViewer.setEditPartFactory(new GraphicalEditPartFactory());
                ScalableFreeformRootEditPart rootEditPart = new ScalableFreeformRootEditPart();
                ((ConnectionLayer) rootEditPart.getLayer(LayerConstants.CONNECTION_LAYER))
                    .setAntialias(SWT.ON);
                graphicalViewer.setRootEditPart(rootEditPart);
                graphicalViewer.setContents(featureModel);
                FeatureDiagramLayoutManager layoutManager = new LevelOrderLayout();
                layoutManager.layout(featureModel);
                GEFImageWriter.writeToFile(graphicalViewer, file);
              }
            };
        conversion.setPriority(Job.LONG);
        conversion.schedule();
      }
    }

    refresh();
  }
  private synchronized Object doAttemptSetTopIndex(final Object topIndexKey) {
    final int i = getVirtualContentModel().indexOfKey(topIndexKey);
    if (i >= 0) {
      UIJob job = new UIJob("set top index") { // $NON-NLS-1$

            public IStatus runInUIThread(IProgressMonitor monitor) {
              if (getTable().isDisposed()) {
                fTopIndexQueue.clear();
                return Status.OK_STATUS;
              }

              int idx = getVirtualContentModel().indexOfKey(topIndexKey);
              if (idx >= 0) {
                if (DebugUIPlugin.DEBUG_DYNAMIC_LOADING) {
                  DebugUIPlugin.trace(
                      "actual set top index: "
                          + ((BigInteger) topIndexKey).toString(16)); // $NON-NLS-1$
                }
                fPendingTopIndexKey = null;
                setTopIndexKey(topIndexKey);
                getTable().setTopIndex(idx);
                tableTopIndexSetComplete();

                if (getTable().getTopIndex() != idx) {
                  if (DebugUIPlugin.DEBUG_DYNAMIC_LOADING) {
                    DebugUIPlugin.trace(
                        ">>> FAILED set top index : "
                            + ((BigInteger) topIndexKey).toString(16)); // $NON-NLS-1$
                  }

                  // only retry if we have pending updates
                  if (hasPendingUpdates()) {
                    if (DebugUIPlugin.DEBUG_DYNAMIC_LOADING) {
                      DebugUIPlugin.trace(
                          ">>> Retry top index: "
                              + ((BigInteger) topIndexKey).toString(16)); // $NON-NLS-1$
                    }

                    fPendingTopIndexKey = topIndexKey;
                  }
                }
              } else {
                if (DebugUIPlugin.DEBUG_DYNAMIC_LOADING) {
                  DebugUIPlugin.trace(
                      "cannot find key, put it back to the queue: " + topIndexKey); // $NON-NLS-1$
                }
                fPendingTopIndexKey = topIndexKey;
              }

              // remove the top index key from queue when it is processed
              removeKeyFromQueue(topIndexKey);

              return Status.OK_STATUS;
            }
          };

      // set top index does not happen immediately, keep track of
      // all pending set top index
      addKeyToQueue(topIndexKey);

      job.setSystem(true);
      job.schedule();
      return topIndexKey;
    }
    return topIndexKey;
  }