public void setupAutoRefresh() {
   if (refreshTask == null) {
     refreshTask =
         rp.create(
             new Runnable() {
               @Override
               public void run() {
                 String selection = comp.getSelectedText();
                 if (selection != null && !isKeyword(selection)) {
                   Pattern p = Pattern.compile(selection);
                   Matcher m = p.matcher(comp.getText());
                   // for some reason the matcher skips the \n chars
                   // so i am finding them all and subtracting them
                   // from the resulting start and end offset.
                   while (m.find() == true) {
                     int startOffset = m.start();
                     int numberOfLineFeed =
                         comp.getText().substring(0, startOffset).split("\n").length - 1;
                     startOffset = startOffset - numberOfLineFeed;
                     int endOffset = m.end() - numberOfLineFeed;
                     bag.addHighlight(startOffset, endOffset, defaultColors);
                   }
                 }
               }
             });
     refreshTask.setPriority(Thread.MIN_PRIORITY);
   }
   refreshTask.schedule(DELAY);
 }
  public void testGetFileWhileClosingProject() throws Exception {

    File projectRoot = getDataFile("quote_nosyshdr");

    int count = Integer.getInteger("test.get.file.while.closing.project.laps", 500);

    final TraceModelBase traceModel = new TraceModelBase(true);
    traceModel.processArguments(projectRoot.getAbsolutePath());
    ModelImpl model = traceModel.getModel();

    List<String> files = new ArrayList<String>(traceModel.getFiles().size());
    for (File file : traceModel.getFiles()) {
      files.add(file.getAbsolutePath());
    }

    for (int i = 0; i < count; i++) {

      System.err.printf(
          "%s: processing project %s. Pass %d \n",
          getBriefClassName(), projectRoot.getAbsolutePath(), i);

      final CsmProject project = traceModel.getProject();
      project.waitParse();
      RequestProcessor.Task task =
          model.enqueueModelTask(
              new Runnable() {

                @Override
                public void run() {
                  TraceModelBase.closeProject(project);
                }
              },
              "Closing Project " + i); // NOI18N
      for (String path : files) {
        try {
          CsmFile csmFile = project.findFile(path, true, false);
          if (verbose) {
            System.err.printf("\tfind %s -> %s \n", path, csmFile);
          }
        } catch (Throwable e) {
          registerException(e);
        }
        assertNoExceptions();
      }
      if (verbose) {
        System.err.printf("Waiting util close task finishes...\n");
      }
      task.waitFinished();
      if (verbose) {
        System.err.printf("\tClose task has finished.\n");
      }
      assertNoExceptions();
      traceModel.resetProject();
    }
    assertNoExceptions();
  }
Exemplo n.º 3
0
  /**
   * Creates a task that will execute the given command.
   *
   * @param cmd command to schedule
   * @param globalOptions options to use when running the command
   * @param mgr listener for command events
   * @return RequestProcessor.Task a task ready to execute the command
   * @throws IllegalCommandException if the command is not valid, e.g. it contains files that cannot
   *     be processed by a single command (they do not have a common filesystem root OR their CVS
   *     Roots differ)
   */
  public RequestProcessor.Task createTask(
      Command cmd, GlobalOptions globalOptions, final ExecutorSupport mgr)
      throws IllegalCommandException {

    File[] files = getCommandFiles(cmd);
    if ((cmd instanceof CheckoutCommand) == false && !(cmd instanceof RlogCommand)) { // XXX
      ensureValidCommand(files);
    }

    if (globalOptions.getCVSRoot() == null) {
      globalOptions = (GlobalOptions) globalOptions.clone();
      globalOptions.setCVSRoot(cvsRoot);
    }

    Client client = createClient();
    if ((cmd instanceof RlogCommand)) { // XXX
    } else if ((cmd instanceof CheckoutCommand)) { // XXX
      BasicCommand bc = (BasicCommand) cmd;
      if (bc.getFiles() != null) {
        String path = bc.getFiles()[0].getAbsolutePath();
        client.setLocalPath(path);
      } else {
        // #67315: use some default working dir
        client.setLocalPath(System.getProperty("user.dir")); // NOI18N
      }
    } else if (cmd instanceof ImportCommand) {
      client.setLocalPath(((ImportCommand) cmd).getImportDirectory());
    } else {
      setLocalDirectory(client, files);
    }

    client.getEventManager().addCVSListener(mgr);
    final CommandRunnable cr = new CommandRunnable(client, globalOptions, cmd, mgr);
    mgr.commandEnqueued(cr);
    RequestProcessor.Task task = requestProcessor.create(cr);
    task.addTaskListener(
        new TaskListener() {
          public void taskFinished(Task task) {
            try {
              // There are times when 'commandTerminated()' is not the last method called, therefore
              // I introduced
              // this event that really marks the very end of a command (thread end)
              mgr.commandTerminated(new TerminationEvent(new Result(cr)));
            } catch (Throwable e) {
              ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
            } finally {
              flushLog();
            }
          }
        });
    return task;
  }
Exemplo n.º 4
0
  /**
   * Shows commit message in status bar and or revision change repaints side bar (to highlight same
   * revision). This process is started in a seperate thread.
   */
  private void onCurrentLine() {
    if (latestAnnotationTask != null) {
      latestAnnotationTask.cancel();
    }

    latestAnnotationTask = getRequestProcessor().post(this);
  }
 /**
  * Restart the timer which starts the parser after the specified delay.
  *
  * @param onlyIfRunning Restarts the timer only if it is already running
  */
 public void restartTimer() {
   if (parsingDocumentTask == null
       || parsingDocumentTask.isFinished()
       || parsingDocumentTask.cancel()) {
     dataObject.setDocumentDirty(true);
     Runnable r =
         new Runnable() {
           public void run() {
             dataObject.parsingDocument();
           }
         };
     if (parsingDocumentTask != null)
       parsingDocumentTask = RequestProcessor.getDefault().post(r, AUTO_PARSING_DELAY);
     else parsingDocumentTask = RequestProcessor.getDefault().post(r, 100);
   }
 }
Exemplo n.º 6
0
 public Node[] getNodes(boolean optimal) {
   if (optimal) {
     Node[] garbage = super.getNodes(false);
     task.waitFinished();
   }
   return super.getNodes(false);
 }
Exemplo n.º 7
0
 private void cancelBackgroundTasks() {
   if (prepareTask != null) {
     prepareTask.cancel();
   }
   if (executeStatusSupport != null) {
     executeStatusSupport.cancel();
   }
 }
Exemplo n.º 8
0
 public void propertyChange(PropertyChangeEvent evt) {
   if (DiffController.PROP_DIFFERENCES.equals(evt.getPropertyName())) {
     refreshComponents();
   } else if (StatusCache.PROP_FILE_STATUS_CHANGED.equals(evt.getPropertyName())) {
     if (!affectsView(evt)) {
       return;
     }
     refreshTask.schedule(200);
   }
 }
 public void propertyChange(java.beans.PropertyChangeEvent evt) {
   if (!dObj.isChangedFromUI()) {
     String name = evt.getPropertyName();
     if (name.indexOf("WebApplicationExt") > 0) { // NOI18
       // repaint view if the wiew is active and something is changed with filters
       if (WEBEXT_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) {
         repaintingTask.schedule(100);
       } else {
         needInit = true;
       }
     }
   }
 }
 @Override
 public void actionPerformed(ActionEvent ev) {
   Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           cssMinify();
         }
       };
   final RequestProcessor.Task theTask = RP.create(runnable);
   final ProgressHandle ph =
       ProgressHandleFactory.createHandle(
           "Minifying CSS " + context.getPrimaryFile().getName(), theTask);
   theTask.addTaskListener(
       new TaskListener() {
         @Override
         public void taskFinished(org.openide.util.Task task) {
           // JOptionPane.showMessageDialog(null, "Image Compressed Successfully");
           ph.finish();
         }
       });
   ph.start();
   theTask.schedule(0);
 }
 public void setupAutoRefresh() {
   if (lastRefreshTask == null) {
     lastRefreshTask =
         rp.create(
             new Runnable() {
               @Override
               public void run() {
                 String selection = comp.getSelectedText();
                 if (selection != null) {
                   Pattern p = Pattern.compile(selection);
                   Matcher m = p.matcher(comp.getText());
                   while (m.find() == true) {
                     int startOffset = m.start();
                     int endOffset = m.end();
                     bag.addHighlight(startOffset, endOffset, defaultColors);
                   }
                 }
               }
             });
   }
   lastRefreshTask.schedule(REFRESH_DELAY);
 }
Exemplo n.º 12
0
  /** Pair method to {@link #annotate}. It releases all resources. */
  private void release() {
    editorUI.removePropertyChangeListener(this);
    textComponent.removeComponentListener(this);
    doc.removeDocumentListener(this);
    caret.removeChangeListener(this);
    if (caretTimer != null) {
      caretTimer.removeActionListener(this);
    }
    elementAnnotations = Collections.<Element, AnnotateLine>emptyMap();
    previousRevisions = null;
    originalFiles = null;
    // cancel running annotation task if active
    if (latestAnnotationTask != null) {
      latestAnnotationTask.cancel();
    }
    AnnotationMarkProvider amp = AnnotationMarkInstaller.getMarkProvider(textComponent);
    if (amp != null) {
      amp.setMarks(Collections.<AnnotationMark>emptyList());
    }

    clearRecentFeedback();
  }
 /** Restart the timer which starts the parser after the specified delay. */
 void restartTimer() {
   timerTask.schedule(200);
 }
Exemplo n.º 14
0
 protected void addNotify() {
   super.addNotify();
   task.schedule(0);
 }
Exemplo n.º 15
0
  private void refreshSetups() {
    if (dpt != null) {
      prepareTask.cancel();
    }

    File[] files;
    switch (currentType) {
      case Setup.DIFFTYPE_LOCAL:
        displayStatuses = StatusInfo.STATUS_LOCAL_CHANGE;
        break;
      case Setup.DIFFTYPE_REMOTE:
        displayStatuses = StatusInfo.STATUS_REMOTE_CHANGE;
        break;
      case Setup.DIFFTYPE_ALL:
        displayStatuses = StatusInfo.STATUS_LOCAL_CHANGE | StatusInfo.STATUS_REMOTE_CHANGE;
        break;
      default:
        throw new IllegalStateException("Unknown DIFF type:" + currentType); // NOI18N
    }
    files = GitUtils.getModifiedFiles(context, displayStatuses);

    setups = computeSetups(files);
    boolean propertyColumnVisible = false;
    for (Setup setup : setups) {
      if (setup.getPropertyName() != null) {
        propertyColumnVisible = true;
        break;
      }
    }
    fileTable.setColumns(
        propertyColumnVisible
            ? new String[] {
              DiffNode.COLUMN_NAME_NAME,
              DiffNode.COLUMN_NAME_PROPERTY,
              DiffNode.COLUMN_NAME_STATUS,
              DiffNode.COLUMN_NAME_LOCATION
            }
            : new String[] {
              DiffNode.COLUMN_NAME_NAME, DiffNode.COLUMN_NAME_STATUS, DiffNode.COLUMN_NAME_LOCATION
            });
    fileTable.setTableModel(setupToNodes(setups));

    if (setups.length == 0) {
      String noContentLabel;
      switch (currentType) {
        case Setup.DIFFTYPE_LOCAL:
          noContentLabel =
              NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoLocalChanges");
          break;
        case Setup.DIFFTYPE_REMOTE:
          noContentLabel =
              NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoRemoteChanges");
          break;
        case Setup.DIFFTYPE_ALL:
          noContentLabel = NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoAllChanges");
          break;
        default:
          throw new IllegalStateException("Unknown DIFF type:" + currentType); // NOI18N
      }
      setups = null;
      fileTable.setTableModel(new Node[0]);
      fileTable.getComponent().setEnabled(false);
      fileTable.getComponent().setPreferredSize(null);
      Dimension dim = fileTable.getComponent().getPreferredSize();
      fileTable.getComponent().setPreferredSize(new Dimension(dim.width + 1, dim.height));
      diffView = null;
      diffView = new NoContentPanel(noContentLabel);
      setBottomComponent();
      nextAction.setEnabled(false);
      prevAction.setEnabled(false);
      revalidate();
      repaint();
    } else {
      fileTable.getComponent().setEnabled(true);
      fileTable.getComponent().setPreferredSize(null);
      Dimension dim = fileTable.getComponent().getPreferredSize();
      fileTable.getComponent().setPreferredSize(new Dimension(dim.width + 1, dim.height));
      setDiffIndex(0, 0);
      dpt = new DiffPrepareTask(setups);
      prepareTask = RequestProcessor.getDefault().post(dpt);
    }
  }
 public boolean cancel() {
   return task.cancel();
 }