public void updateProgress(
      final InetAddress currentAddress, final int runningThreads, final int percentageComplete) {
    if (display.isDisposed()) return;
    display.asyncExec(
        new Runnable() {
          public void run() {
            if (statusBar.isDisposed()) return;

            // update status bar
            if (currentAddress != null) {
              statusBar.setStatusText(
                  Labels.getLabel("state.scanning") + currentAddress.getHostAddress());
            }
            statusBar.setRunningThreads(runningThreads);
            statusBar.setProgress(percentageComplete);

            // show percentage in main window title
            if (!stateMachine.inState(ScanningState.IDLE))
              statusBar.getShell().setText(percentageComplete + "% - " + mainWindowTitle);
            else statusBar.getShell().setText(mainWindowTitle);

            // change button image according to the current state
            button.setImage(buttonImages[stateMachine.getState().ordinal()]);
          }
        });
  }
Пример #2
0
  public void transactionEnded(Transaction transaction) {
    IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
    for (int i = 0; i < windows.length; ++i) {
      IWorkbenchPage[] pages = windows[i].getPages();
      for (int j = 0; j < pages.length; ++j) {
        IViewReference[] views = pages[j].getViewReferences();
        for (int k = 0; k < views.length; ++k) {
          if (views[k].getPart(false) instanceof PropertySheet) {
            final PropertySheet ps = (PropertySheet) views[k].getPart(false);
            if (ps.getCurrentPage() instanceof PropertySheetPage) {
              final PropertySheetPage psp = (PropertySheetPage) ps.getCurrentPage();

              Display d2 = PlatformUI.getWorkbench().getDisplay();
              if (d2 == null) {
                d2 = Ooaofooa.m_display;
              }
              if (d2 != null) {
                // always run async to prevent infinite loops
                // when the update comes from the property view
                d2.asyncExec(
                    new Runnable() {
                      public void run() {
                        if (!psp.getControl().isDisposed()) psp.refresh();
                      }
                    });
              }
              break;
            }
          }
        }
      }
    }
  }
  /**
   * Adds this as element state listener in the UI thread as it can otherwise conflict with other
   * listener additions, since DocumentProvider is not thread-safe.
   *
   * @param editor the editor to get the display from
   * @param provider the document provider to register as element state listener
   */
  private void addElementStateListener(ITextEditor editor, final IDocumentProvider provider) {
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=66686 and
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56871

    Runnable runnable =
        new Runnable() {
          public void run() {
            synchronized (fLock) {
              if (fDocumentProvider == provider)
                // addElementStateListener adds at most once - no problem to call repeatedly
                provider.addElementStateListener(LastSaveReferenceProvider.this);
            }
          }
        };

    Display display = null;
    if (editor != null) {
      IWorkbenchPartSite site = editor.getSite();
      if (site != null) {
        IWorkbenchWindow window = site.getWorkbenchWindow();
        if (window != null) {
          Shell shell = window.getShell();
          if (shell != null) display = shell.getDisplay();
        }
      }
    }

    if (display != null && !display.isDisposed()) {
      display.asyncExec(runnable);
    } else {
      runnable.run();
    }
  }
Пример #4
0
  private void pushUpstream(final RevCommit commit) {
    RemoteConfig config = SimpleConfigurePushDialog.getConfiguredRemote(repository);
    if (config == null) {
      final Display display = Display.getDefault();
      display.asyncExec(
          new Runnable() {

            public void run() {
              try {
                PushBranchWizard pushWizard = null;
                String fullBranch = repository.getFullBranch();
                if (fullBranch != null && fullBranch.startsWith(Constants.R_HEADS)) {
                  Ref ref = repository.getRef(fullBranch);
                  pushWizard = new PushBranchWizard(repository, ref);
                } else {
                  pushWizard = new PushBranchWizard(repository, commit.getId());
                }
                WizardDialog wizardDialog = new WizardDialog(display.getActiveShell(), pushWizard);
                wizardDialog.setHelpAvailable(true);
                wizardDialog.open();
              } catch (IOException e) {
                Activator.handleError(NLS.bind(UIText.CommitUI_pushFailedMessage, e), e, true);
              }
            }
          });
    } else {
      PushOperationUI op = new PushOperationUI(repository, config.getName(), false);
      op.start();
    }
  }
Пример #5
0
 private void displayExec(Runnable r) {
   synchronized (Device.class) {
     if (!display.isDisposed()) {
       display.asyncExec(r);
     }
   }
 }
  /**
   * Update the presentation.
   *
   * @param textPresentation the text presentation
   * @param addedPositions the added positions
   * @param removedPositions the removed positions
   */
  private void updatePresentation(
      TextPresentation textPresentation,
      List<Position> addedPositions,
      List<Position> removedPositions) {
    Runnable runnable =
        fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
    if (runnable == null) {
      return;
    }

    DartEditor editor = fEditor;
    if (editor == null) {
      return;
    }

    IWorkbenchPartSite site = editor.getSite();
    if (site == null) {
      return;
    }

    Shell shell = site.getShell();
    if (shell == null || shell.isDisposed()) {
      return;
    }

    Display display = shell.getDisplay();
    if (display == null || display.isDisposed()) {
      return;
    }

    display.asyncExec(runnable);
  }
Пример #7
0
  private void onOwnerShellEvent(final Event event) {

    if (_shell == null || _shell.isDisposed()) {
      return;
    }

    switch (event.type) {
      case SWT.Deactivate:
        _display.asyncExec(
            new Runnable() {

              public void run() {

                // hide tooltip when another shell is activated

                if (_display.getActiveShell() != _shell) {
                  ttHide();
                }
              }
            });
        break;

      case SWT.Move:
        showShellWhenVisible();

        break;
    }
  }
Пример #8
0
 @Override
 public void run() {
   // use my class for library loading
   try {
     Display display = Display.getDefault();
     final Shell splash = createSplash(display);
     final Shell content = new Shell(display);
     splash.open();
     display.asyncExec(
         new Runnable() {
           @Override
           public void run() {
             runContent(content);
             content.open();
             splash.close();
           }
         });
     while (!splash.isDisposed() || !content.isDisposed()) {
       if (!display.readAndDispatch()) display.sleep();
     }
     if (sandbox != null) sandbox.shutdown();
     display.dispose();
   } catch (Throwable e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } finally {
     System.err.flush();
     System.out.flush();
     System.exit(0);
   }
 }
Пример #9
0
  @Override
  @SuppressWarnings("restriction")
  protected IStatus run(IProgressMonitor monitor) {
    try {
      Gist gist = new Gist().setPublic(isPublic);
      gist.setDescription(title);
      GistFile file = new GistFile().setContent(content);
      gist.setFiles(Collections.singletonMap(title, file));
      final Gist created = service.createGist(gist);
      final Display display = PlatformUI.getWorkbench().getDisplay();
      display.asyncExec(
          new Runnable() {

            public void run() {
              GistNotificationPopup popup =
                  new GistNotificationPopup(display, created, title, repository);
              popup.create();
              popup.open();
            }
          });
      TasksUiPlugin.getTaskJobFactory()
          .createSynchronizeRepositoriesJob(GistConnectorUi.getRepositories())
          .schedule();
    } catch (IOException e) {
      GitHubUi.logError(GitHubException.wrap(e));
    }
    return Status.OK_STATUS;
  }
Пример #10
0
  /**
   * {@inheritDoc}
   *
   * @since 7.1
   */
  public void handleEvent(final CProjectDescriptionEvent event) {
    Display display = Display.getDefault();
    display.asyncExec(
        new Runnable() {
          public void run() {
            ICDescriptionDelta delta = event.getDefaultSettingCfgDelta();
            if (delta == null) return;

            int flags = delta.getChangeFlags();
            if (((flags & ICDescriptionDelta.SOURCE_ADDED) != 0)
                || ((flags & ICDescriptionDelta.SOURCE_REMOVED) != 0)) {

              IProject project = null;
              ICSettingObject setting = delta.getOldSetting();
              if (setting == null) setting = delta.getNewSetting();

              if (setting instanceof ICConfigurationDescription)
                project =
                    ((ICConfigurationDescription) setting).getProjectDescription().getProject();

              if (project != null) viewer.refresh(project);
              else viewer.refresh();
            }
          }
        });
  }
 /**
  * Log and display balloon message according to log level.
  *
  * @param message text message
  * @param level log level
  */
 public void displayMessage(final String message, final Level level) {
   if (trayItem != null) {
     display.asyncExec(
         new Runnable() {
           public void run() {
             int messageType = 0;
             if (level.equals(Level.INFO)) {
               messageType = SWT.ICON_INFORMATION;
             } else if (level.equals(Level.WARN)) {
               messageType = SWT.ICON_WARNING;
             } else if (level.equals(Level.ERROR)) {
               messageType = SWT.ICON_ERROR;
             }
             if (messageType != 0) {
               final ToolTip toolTip = new ToolTip(shell, SWT.BALLOON | messageType);
               toolTip.setText(BundleMessage.format("UI_DAVMAIL_GATEWAY"));
               toolTip.setMessage(message);
               trayItem.setToolTip(toolTip);
               toolTip.setVisible(true);
             }
             trayItem.setToolTipText(BundleMessage.format("UI_DAVMAIL_GATEWAY") + '\n' + message);
           }
         });
   }
 }
Пример #12
0
 private void doneLoadChildren(
     final FileInfo parent, final Throwable error, final FileInfo[] children) {
   assert Protocol.isDispatchThread();
   assert error == null || children == null;
   if (fDisplay == null) return;
   Arrays.sort(
       children,
       new Comparator<FileInfo>() {
         public int compare(FileInfo o1, FileInfo o2) {
           if (o1.isDir == o2.isDir) return o1.name.compareTo(o2.name);
           if (o1.isDir) return 1;
           return -1;
         }
       });
   int i = 0;
   for (FileInfo fileInfo : children) {
     fileInfo.index = i++;
   }
   fDisplay.asyncExec(
       new Runnable() {
         public void run() {
           assert parent.children_pending;
           assert parent.children == null;
           parent.children_pending = false;
           parent.children = children;
           parent.children_error = error;
           updateItems(parent);
         }
       });
 }
Пример #13
0
  private void exec(Runnable runnable, boolean async) {
    try {
      Display display = getDisplay();

      /*
       * this will not work, although the chance is really small, it is
       * possible that the device is disposed after this check and before
       * the a(sync)Exec call
       */
      // if (display.isDisposed())
      // return;

      if (async) display.asyncExec(runnable);
      else display.syncExec(runnable);

    } catch (SWTException e) {

      if (PlatformUI.getWorkbench().isClosing()) {
        LOG.warn(
            "could not execute runnable " + runnable + ", UI thread is not available",
            new StackTrace());
      } else {
        LOG.error(
            "could not execute runnable "
                + runnable
                + ", workbench display was disposed before workbench shutdown",
            e);
      }
    }
  }
Пример #14
0
 private void exec(Runnable runnable) {
   if (canvas == null) return;
   if (canvas.isDisposed()) return;
   Display display = canvas.getDisplay();
   if (!display.isDisposed()) {
     display.asyncExec(runnable);
   }
 }
Пример #15
0
 public static void tryAsyncExec(final IWorkbenchPartSite site, final Runnable runnable) {
   if (site == null) return;
   final Shell shell = site.getShell();
   if (shell == null) return;
   final Display display = shell.getDisplay();
   if (display == null) return;
   display.asyncExec(runnable);
 }
 protected static void openDialog(final IDialog<?> dialog, final Display display) {
   display.asyncExec(
       new Runnable() {
         public void run() {
           dialog.open();
         }
       });
 }
 public void updateItems(final String[] inItems) {
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           if (cellEditor != null) cellEditor.setItems(inItems);
         }
       });
 }
Пример #18
0
 @Override
 public void revealEndOfDocument() {
   final Display display = UIAccess.getDisplay();
   display.asyncExec(
       new Runnable() {
         public void run() {
           final StyledText textWidget = getTextWidget();
           if (!UIAccess.isOkToUse(textWidget)) {
             return;
           }
           final AbstractDocument document = (AbstractDocument) getDocument();
           final long timestamp = document.getModificationStamp();
           final int lineCount = textWidget.getLineCount();
           final int lineToShow =
               ((lineCount > 1
                       && textWidget.getCharCount() == textWidget.getOffsetAtLine(lineCount - 1))
                   ? (lineCount - 1)
                   : (lineCount));
           final int visiblePixel = textWidget.getClientArea().height;
           final int linePixel = textWidget.getLineHeight();
           final int topPixel = (linePixel * (lineToShow - 1)) - visiblePixel + 2;
           if (topPixel + linePixel > 0) {
             if (topPixel < 0) {
               textWidget.setTopPixel(topPixel + linePixel);
             } else {
               final int[] move =
                   new int[] {
                     topPixel,
                     topPixel + linePixel - 2,
                     topPixel + linePixel - 1,
                     topPixel + linePixel
                   };
               textWidget.setTopPixel(move[0]);
               final int[] state = new int[] {1};
               display.timerExec(
                   75,
                   new Runnable() {
                     public void run() {
                       int i = state[0];
                       if (!UIAccess.isOkToUse(textWidget)
                           || timestamp
                               != ((IDocumentExtension4) getDocument()).getModificationStamp()
                           || move[i - 1] != textWidget.getTopPixel()) {
                         return;
                       }
                       textWidget.setTopPixel(move[i++]);
                       if (i < move.length) {
                         state[0] = i;
                         display.timerExec(25, this);
                       }
                     }
                   });
             }
           }
         }
       });
 }
Пример #19
0
  private void onTTAllControlsEvent(final Event event) {

    if (_shell == null || _shell.isDisposed()) {
      return;
    }

    switch (event.type) {
      case SWT.KeyDown:
        if (event.keyCode == SWT.ESC) {
          hide();
        }

        break;

      case SWT.MouseEnter:
        if (_isShellFadingIn || _isShellFadingOut) {

          // stop animation
          //				_isShellFadingIn = _isShellFadingOut = false;
        }

        break;

      case SWT.MouseExit:
        break;

      case SWT.MouseMove:
        if (_isReceiveOnMouseMove //
        //					&& _isShellFadingIn == false
        //					&& _isShellFadingOut == false//
        ) {

          final Widget widget = event.widget;

          if (widget instanceof Control) {

            final Point ttDisplayLocation = ((Control) widget).toDisplay(event.x, event.y);
            final Point ownerLocation = _ownerControl.toControl(ttDisplayLocation);

            _display.asyncExec(
                new Runnable() {
                  public void run() {

                    final MouseEvent mouseEvent = new MouseEvent(event);
                    mouseEvent.x = ownerLocation.x;
                    mouseEvent.y = ownerLocation.y;

                    onMouseMoveInToolTip(mouseEvent);
                  }
                });
          }
        }

        break;
    }
  }
Пример #20
0
    /** Posts this runnable into the event queue. */
    public void post(IContentOutlinePage page) {
      this.page = page;
      if (posted) return;

      Display d = Display.getDefault();
      if (d != null && !d.isDisposed()) {
        posted = true;
        d.asyncExec(this);
      }
    }
Пример #21
0
 private void redraw(Display display) {
   display.asyncExec(
       new Runnable() {
         public void run() {
           if (control != null && !control.isDisposed()) {
             control.redraw();
           }
         }
       });
 }
Пример #22
0
 public static void postEvent(Control ownerControl, final Event event) {
   final Display display = ownerControl.getDisplay();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           display.post(event);
         }
       });
 }
Пример #23
0
 public void close(final boolean save) {
   final Display display = getSite().getShell().getDisplay();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           getSite().getPage().closeEditor(RDataEditor.this, save);
         }
       });
 }
Пример #24
0
    /** Posts this runnable into the event queue. */
    public void postMessage(String message) {
      this.message = message;
      if (posted) return;

      Display d = Display.getDefault();
      if (d != null && !d.isDisposed()) {
        posted = false;
        d.asyncExec(this);
      }
    }
  private void updateBatonCanvas() {
    display.asyncExec(
        new Runnable() {

          @Override
          public void run() {
            canvas.redraw();
            canvas.update();
          }
        });
  }
 @Override
 public void finished(final JobTreeElement jte) {
   final Display display = Display.getDefault();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           refresh();
         }
       });
 }
 @Override
 public void removed(JobTreeElement info) {
   final Display display = Display.getDefault();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           refresh();
         }
       });
 }
  /**
   * Update the presentation.
   *
   * @param textPresentation the text presentation
   * @param addedPositions the added positions
   * @param removedPositions the removed positions
   */
  private void updatePresentation(
      TextPresentation textPresentation,
      List<AttributedPosition> addedPositions,
      List<AttributedPosition> removedPositions) {
    Runnable runnable =
        presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
    if (runnable == null) return;

    Display display = getDisplay();
    display.asyncExec(runnable);
  }
 /**
  * Executes the given runnable in the UI thread. If method is called in UI thread, then runnable
  * is executed immediately, otherwise it's executed using <code>Display.asyncExec()</code>.
  * Runnable is not executed if update is canceled or content provider is disposed.
  *
  * @since 3.8
  */
 protected void execInDisplayThread(Runnable runnable) {
   ITreeModelViewer viewer = getContentProvider().getViewer();
   if (viewer != null && !isCanceled()) {
     Display display = viewer.getDisplay();
     if (Thread.currentThread() == display.getThread()) {
       runnable.run();
     } else {
       display.asyncExec(runnable);
     }
   }
 }
Пример #30
0
  /*
   * (non-Javadoc)
   * @see org.overture.ide.plugins.rttraceviewer.viewer.IViewCallback#showMessage(java .lang.String)
   */
  public void showMessage(final String message) {
    display.asyncExec(
        new Runnable() {

          public void run() {

            cw.println(message);
            cw.show();
          }
        });
  }