コード例 #1
0
  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;
            }
          }
        }
      }
    }
  }
コード例 #3
0
  /**
   * 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
ファイル: CommitJob.java プロジェクト: blizzy78/egit
  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
ファイル: TCFAnnotationManager.java プロジェクト: eclipse/tcf
 private void displayExec(Runnable r) {
   synchronized (Device.class) {
     if (!display.isDisposed()) {
       display.asyncExec(r);
     }
   }
 }
コード例 #6
0
  /**
   * 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
ファイル: GLSandBox.java プロジェクト: MMesbahU/caleydo
 @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
ファイル: MakeContentProvider.java プロジェクト: alblue/cdt
  /**
   * {@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();
            }
          }
        });
  }
コード例 #11
0
 /**
  * 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
ファイル: SWTSynchronizer.java プロジェクト: Gleydar/saros
  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
ファイル: GameView.java プロジェクト: fogleman/WordWarrior
 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
ファイル: UiThreadHelper.java プロジェクト: haku/Morrigan
 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);
 }
コード例 #16
0
 protected static void openDialog(final IDialog<?> dialog, final Display display) {
   display.asyncExec(
       new Runnable() {
         public void run() {
           dialog.open();
         }
       });
 }
コード例 #17
0
 public void updateItems(final String[] inItems) {
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           if (cellEditor != null) cellEditor.setItems(inItems);
         }
       });
 }
コード例 #18
0
ファイル: OutputViewer.java プロジェクト: akbertram/statet
 @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
ファイル: SpellingHelper.java プロジェクト: nickmain/xmind
 private void redraw(Display display) {
   display.asyncExec(
       new Runnable() {
         public void run() {
           if (control != null && !control.isDisposed()) {
             control.redraw();
           }
         }
       });
 }
コード例 #22
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 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
ファイル: RDataEditor.java プロジェクト: baihualong/statet
 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);
      }
    }
コード例 #25
0
  private void updateBatonCanvas() {
    display.asyncExec(
        new Runnable() {

          @Override
          public void run() {
            canvas.redraw();
            canvas.update();
          }
        });
  }
コード例 #26
0
 @Override
 public void finished(final JobTreeElement jte) {
   final Display display = Display.getDefault();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           refresh();
         }
       });
 }
コード例 #27
0
 @Override
 public void removed(JobTreeElement info) {
   final Display display = Display.getDefault();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           refresh();
         }
       });
 }
コード例 #28
0
  /**
   * 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);
  }
コード例 #29
0
 /**
  * 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
ファイル: VdmRtLogEditor.java プロジェクト: henriknj/overture
  /*
   * (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();
          }
        });
  }