protected void updateStatus(IStatus status) {
   if (!status.matches(IStatus.ERROR)) {
     for (int i = 0; i < fNumberFields.size(); i++) {
       Text text = fNumberFields.get(i);
       IStatus s = validatePositiveNumber(text.getText());
       status = StatusUtil.getMoreSevere(s, status);
     }
   }
   // status= StatusUtil.getMoreSevere(fCEditorHoverConfigurationBlock.getStatus(), status);
   setValid(!status.matches(IStatus.ERROR));
   StatusUtil.applyToStatusLine(this, status);
 }
 private Image findImage(IStatus status) {
   if (status.isOK()) {
     return null;
   } else if (status.matches(IStatus.ERROR)) {
     return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
   } else if (status.matches(IStatus.WARNING)) {
     return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
   } else if (status.matches(IStatus.INFO)) {
     return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
   }
   return null;
 }
  private void populateList(List list, IStatus status, int nesting) {
    if (!status.matches(MASK)) {
      return;
    }
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < nesting; i++) {
      buffer.append(NESTING_INDENT);
    }
    buffer.append(status.getMessage());
    list.add(buffer.toString());

    // Look for a nested core exception
    Throwable t = status.getException();
    if (t instanceof CoreException) {
      CoreException ce = (CoreException) t;
      populateList(list, ce.getStatus(), nesting + 1);
    } else if (t != null) {
      // Include low-level exception message
      buffer = new StringBuffer();
      for (int i = 0; i < nesting; i++) {
        buffer.append(NESTING_INDENT);
      }
      String message = t.getLocalizedMessage();
      if (message == null) {
        message = t.toString();
      }
      buffer.append(message);
      list.add(buffer.toString());
    }

    IStatus[] children = status.getChildren();
    for (int i = 0; i < children.length; i++) {
      populateList(list, children[i], nesting + 1);
    }
  }
 private static void checkStatus(IStatus status) throws FacadeException {
   if (status.matches(IStatus.ERROR)) {
     throw new FacadeException(
         MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(status),
         StatusTool.findException(status));
   }
 }
 protected void numberFieldChanged(Text textControl) {
   String number = textControl.getText();
   IStatus status = validatePositiveNumber(number);
   if (!status.matches(IStatus.ERROR))
     fOverlayStore.setValue(fTextFields.get(textControl), number);
   updateStatus(status);
 }
Exemple #6
0
 private void performNewSearch(final IErlElement element) {
   final ErlangExternalFunctionCallRef ref = SearchUtil.getRefFromErlElement(element);
   final ErlSearchQuery query =
       new ErlSearchQuery(
           ref, IErlSearchConstants.REFERENCES, IErlSearchConstants.FUNCTION, getScope());
   if (query.canRunInBackground()) {
     /*
      * This indirection with Object as parameter is needed to prevent
      * the loading of the Search plug-in: the VM verifies the method
      * call and hence loads the types used in the method signature,
      * eventually triggering the loading of a plug-in (in this case
      * ISearchQuery results in Search plug-in being loaded).
      */
     NewSearchUI.runQueryInBackground(query);
   } else {
     final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
     /*
      * This indirection with Object as parameter is needed to prevent
      * the loading of the Search plug-in: the VM verifies the method
      * call and hence loads the types used in the method signature,
      * eventually triggering the loading of a plug-in (in this case it
      * would be ISearchQuery).
      */
     final IStatus status = NewSearchUI.runQueryInForeground(progressService, query);
     if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
       ErrorDialog.openError(
           getShell(),
           "SearchMessages.Search_Error_search_title",
           "SearchMessages.Search_Error_search_message",
           status);
     }
   }
 }
  private IStatus validateFileName() {
    fileName = null;

    String str = fileNameField.getText().trim();
    if (str.length() == 0) {
      return Util.newErrorStatus("Enter a file name");
    }

    // Validate the file name
    IStatus nameStatus = ResourcesPlugin.getWorkspace().validateName(str, IResource.FILE);
    if (nameStatus.matches(IStatus.ERROR)) {
      return Util.newErrorStatus("Invalid file name. {0}", nameStatus.getMessage());
    }

    // Make sure the host page doesn't already exist in the public path
    if (hostPagePath != null) {
      IPath htmlFilePath =
          hostPagePath
              .append(str)
              .removeFileExtension()
              .addFileExtension(((AbstractNewFileWizard) getWizard()).getFileExtension());
      IFile htmlFile = ResourcesPlugin.getWorkspace().getRoot().getFile(htmlFilePath);
      if (htmlFile.exists()) {
        return Util.newErrorStatus("''{0}'' already exists", htmlFilePath.toString());
      }
    }

    fileName = str;
    return Status.OK_STATUS;
  }
 /* (non-Javadoc)
  * @see org.apache.tools.ant.Task#execute()
  */
 public void execute() throws BuildException {
   try {
     prepareSourceRepos();
     application.initializeRepos(null);
     List<IInstallableUnit> ius = prepareIUs();
     if ((ius == null || ius.size() == 0)
         && !(application.hasArtifactSources() || application.hasMetadataSources()))
       throw new BuildException(Messages.exception_needIUsOrNonEmptyRepo);
     application.setSourceIUs(ius);
     ((Repo2Runnable) application).setFlagAsRunnable(flagAsRunnable);
     ((Repo2Runnable) application).setCreateFragments(createFragments);
     IStatus result = application.run(null);
     if (failOnError && result.matches(IStatus.ERROR)) throw new ProvisionException(result);
   } catch (ProvisionException e) {
     if (failOnError)
       throw new BuildException(
           NLS.bind(
               Messages.Repo2RunnableTask_errorTransforming,
               null != e.getMessage() ? e.getMessage() : e.toString()),
           e);
     /* else */
     getProject()
         .log(
             NLS.bind(
                 Messages.Repo2RunnableTask_errorTransforming,
                 null != e.getMessage() ? e.getMessage() : e.toString()),
             Project.MSG_WARN);
     getProject().log(e.getMessage(), Project.MSG_WARN);
   }
 }
  /**
   * Obtains the first in an array of <code>statuses</code> that has the specified <code>severity
   * </code>.
   *
   * @param statuses an array of statuses. Must not be <code>null</code> or a zero-length array
   * @param severity the severity to look for
   * @return the first status found with this <code>severity</code>, or the first in the array if
   *     none is found
   */
  static IStatus getFirstStatus(IStatus[] statuses, int severity) {
    for (IStatus element : statuses) {
      if (element.matches(severity)) {
        return element;
      }
    }

    return statuses[0];
  }
 private void updateStatus(IStatus status) {
   pageStatus = status;
   setPageComplete(!status.matches(IStatus.ERROR));
   if (pageVisible) {
     if (status.isOK()) {
       setErrorMessage(null);
       setMessage(null);
     } else {
       StatusUtil.applyToStatusLine(this, status);
     }
   }
 }
Exemple #11
0
 /**
  * Finds the most severe status from a array of stati. An error is more severe than a warning, and
  * a warning is more severe than ok.
  *
  * @param status an array of stati
  * @return the most severe status
  */
 public static IStatus getMostSevere(IStatus[] status) {
   IStatus max = null;
   for (int i = 0; i < status.length; i++) {
     IStatus curr = status[i];
     if (curr.matches(IStatus.ERROR)) {
       return curr;
     }
     if (max == null || curr.getSeverity() > max.getSeverity()) {
       max = curr;
     }
   }
   return max;
 }
Exemple #12
0
  private IStatus initializeTouchpointParameters(
      IProfile profile, Operand operand, Touchpoint touchpoint, IProgressMonitor monitor) {
    if (touchpointToTouchpointOperandParameters.containsKey(touchpoint)) return Status.OK_STATUS;

    Map<String, Object> touchpointPhaseParameters =
        touchpointToTouchpointPhaseParameters.get(touchpoint);
    if (touchpointPhaseParameters == null) {
      touchpointPhaseParameters = new HashMap<String, Object>(phaseParameters);
      IStatus status =
          touchpoint.initializePhase(monitor, profile, phaseId, touchpointPhaseParameters);
      if (status != null && status.matches(IStatus.ERROR | IStatus.CANCEL)) return status;
      touchpointToTouchpointPhaseParameters.put(touchpoint, touchpointPhaseParameters);
    }

    Map<String, Object> touchpointOperandParameters =
        new HashMap<String, Object>(touchpointPhaseParameters);
    touchpointOperandParameters.putAll(operandParameters);
    IStatus status = touchpoint.initializeOperand(profile, touchpointOperandParameters);
    if (status != null && status.matches(IStatus.ERROR | IStatus.CANCEL)) return status;
    touchpointToTouchpointOperandParameters.put(touchpoint, touchpointOperandParameters);
    return Status.OK_STATUS;
  }
Exemple #13
0
  private static int collectErrorStatus(OutputStream stream, ArrayList<IStatus> list) {
    IStatus status = getStatus(stream);
    if (!status.isOK()) list.add(status);
    if (status.matches(IStatus.ERROR))
      // Errors past this should be bogus as they rely on output from this step
      return status.getSeverity();

    OutputStream destination = getDestination(stream);
    if (destination == null || !(destination instanceof IStateful)) return status.getSeverity();
    int result = collectErrorStatus(destination, list);
    // TODO greater than test here is a little brittle but it is very unlikely that we will add
    // a new status severity.
    return status.getSeverity() > result ? status.getSeverity() : result;
  }
  @Override
  public void setVisible(boolean visible) {
    super.setVisible(visible);
    pageVisible = visible;

    // Wizards are not allowed to start up with an error message
    if (visible) {
      setFocus();

      if (pageStatus.matches(IStatus.ERROR)) {
        StatusInfo status = new StatusInfo();
        status.setError("");
        pageStatus = status;
      }
    }
  }
Exemple #15
0
  /* @Override */
  public boolean performReplace() {
    try {
      IStatus status =
          NewSearchUI.runQueryInForeground(getContainer().getRunnableContext(), newQuery());
      if (status.matches(IStatus.CANCEL)) {
        return false;
      }
      if (!status.isOK()) {
        ErrorDialog.openError(
            getShell(),
            SearchMessages.TextSearchPage_replace_searchproblems_title,
            SearchMessages.TextSearchPage_replace_runproblem_message,
            status);
      }

      Display.getCurrent()
          .asyncExec(
              new Runnable() {
                @Override
                public void run() {
                  /* ISearchResultViewPart view = */ NewSearchUI.activateSearchResultView();
                  // refactoring support
                  //          if (view != null) {
                  //            ISearchResultPage page = view.getActivePage();
                  //            if (page instanceof FileSearchPage) {
                  //              FileSearchPage filePage = (FileSearchPage) page;
                  //              new ReplaceAction(filePage.getSite().getShell(),
                  //                  (FileSearchResult) filePage.getInput(), null).run();
                  //            }
                  //          }
                }
              });
      return true;
    } catch (CoreException e) {
      ErrorDialog.openError(
          getShell(),
          SearchMessages.TextSearchPage_replace_searchproblems_title,
          SearchMessages.TextSearchPage_replace_querycreationproblem_message,
          e.getStatus());
      return false;
    }
  }
  private IStatus validatePath() {
    hostPagePath = null;

    pathField.enableButton(hostPageProject != null);

    String str = pathField.getText().trim();
    if (str.length() == 0) {
      return Util.newErrorStatus("Enter the file path");
    }

    if (hostPageProject == null) {
      // The rest of the path validation relies on having a valid project, so if
      // we don't have one, bail out here with an OK (the project's error will
      // supercede this one).
      return Status.OK_STATUS;
    }

    IPath path = new Path(hostPageProject.getName()).append(str).makeAbsolute();
    IStatus pathStatus =
        ResourcesPlugin.getWorkspace().validatePath(path.toString(), IResource.FOLDER);
    if (pathStatus.matches(IStatus.ERROR)) {
      return Util.newErrorStatus("Invalid path. {0}", pathStatus.getMessage());
    }

    // Path is valid
    hostPagePath = path;

    IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
    if (!folder.exists()) {
      return Util.newWarningStatus(
          MessageFormat.format(
              "The path ''{0}'' does not exist.  It will be created when you click Finish.",
              path.toString()));
    }

    return Status.OK_STATUS;
  }
 private void statusChanged(final IStatus status) {
   final boolean valid = !status.matches(IStatus.ERROR);
   setValid(valid);
   EditorPreferencePage.applyToStatusLine(this, status);
 }
 private void updateStatus(IStatus status) {
   setValid(!status.matches(IStatus.ERROR));
   StatusUtil.applyToStatusLine(this, status);
 }
Exemple #19
0
  private void mainPerform(
      MultiStatus status, EngineSession session, Operand[] operands, SubMonitor subMonitor) {
    IProfile profile = session.getProfile();
    subMonitor.beginTask(null, operands.length);
    for (int i = 0; i < operands.length; i++) {
      subMonitor.setWorkRemaining(operands.length - i);
      if (subMonitor.isCanceled()) throw new OperationCanceledException();
      Operand operand = operands[i];
      if (!isApplicable(operand)) continue;

      session.recordOperandStart(operand);
      List<ProvisioningAction> actions = getActions(operand);
      operandParameters = new HashMap<String, Object>(phaseParameters);
      operandParameters.put(PARM_OPERAND, operand);
      mergeStatus(status, initializeOperand(profile, operand, operandParameters, subMonitor));
      if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
        operandParameters = null;
        return;
      }

      Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT);
      if (operandTouchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(profile, operand, operandTouchpoint, subMonitor));
        if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

        operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint);
      }

      operandParameters = Collections.unmodifiableMap(operandParameters);
      if (actions != null) {
        for (int j = 0; j < actions.size(); j++) {
          ProvisioningAction action = actions.get(j);
          Map<String, Object> parameters = operandParameters;
          Touchpoint touchpoint = action.getTouchpoint();
          if (touchpoint != null) {
            mergeStatus(
                status, initializeTouchpointParameters(profile, operand, touchpoint, subMonitor));
            if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

            parameters = touchpointToTouchpointOperandParameters.get(touchpoint);
          }
          IStatus actionStatus = null;
          try {
            session.recordActionExecute(action, parameters);
            actionStatus = action.execute(parameters);
          } catch (RuntimeException e) {
            if (!forced) throw e;
            // "action.execute" calls user code and might throw an unchecked exception
            // we catch the error here to gather information on where the problem occurred.
            actionStatus =
                new Status(
                    IStatus.ERROR,
                    EngineActivator.ID,
                    NLS.bind(Messages.forced_action_execute_error, action.getClass().getName()),
                    e);
          } catch (LinkageError e) {
            if (!forced) throw e;
            // Catch linkage errors as these are generally recoverable but let other Errors
            // propagate (see bug 222001)
            actionStatus =
                new Status(
                    IStatus.ERROR,
                    EngineActivator.ID,
                    NLS.bind(Messages.forced_action_execute_error, action.getClass().getName()),
                    e);
          }
          if (forced && actionStatus != null && actionStatus.matches(IStatus.ERROR)) {
            MultiStatus result =
                new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null);
            result.add(
                new Status(
                    IStatus.ERROR,
                    EngineActivator.ID,
                    session.getContextString(this, operand, action),
                    null));
            LogHelper.log(result);
            actionStatus = Status.OK_STATUS;
          }
          mergeStatus(status, actionStatus);
          if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;
        }
      }
      mergeStatus(
          status, touchpointCompleteOperand(profile, operand, operandParameters, subMonitor));
      mergeStatus(status, completeOperand(profile, operand, operandParameters, subMonitor));
      if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;
      operandParameters = null;
      session.recordOperandEnd(operand);
      subMonitor.worked(1);
    }
  }
 protected void updateStatus(IStatus status) {
   setPageComplete(!status.matches(IStatus.ERROR));
   applyStatus(status);
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener#statusChanged(org.eclipse.core.runtime.IStatus)
  */
 public void statusChanged(IStatus status) {
   setValid(!status.matches(IStatus.ERROR));
   StatusUtil.applyToStatusLine(this, status);
 }
Exemple #22
0
  void undo(
      MultiStatus status,
      EngineSession session,
      IProfile profile,
      Operand operand,
      ProvisioningAction[] actions,
      ProvisioningContext context) {
    if (operandParameters == null) {
      operandParameters = new HashMap<String, Object>(phaseParameters);
      operandParameters.put(PARM_OPERAND, operand);
      mergeStatus(
          status,
          initializeOperand(profile, operand, operandParameters, new NullProgressMonitor()));
      Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT);
      if (operandTouchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(
                profile, operand, operandTouchpoint, new NullProgressMonitor()));
        if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

        operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint);
      }
      operandParameters = Collections.unmodifiableMap(operandParameters);
    }
    for (int j = 0; j < actions.length; j++) {
      ProvisioningAction action = actions[j];
      Map<String, Object> parameters = operandParameters;
      Touchpoint touchpoint = action.getTouchpoint();
      if (touchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(
                profile, operand, touchpoint, new NullProgressMonitor()));
        if (status.matches(IStatus.ERROR)) return;

        parameters = touchpointToTouchpointOperandParameters.get(touchpoint);
      }
      IStatus actionStatus = null;
      try {
        session.recordActionUndo(action, parameters);
        actionStatus = action.undo(parameters);
      } catch (RuntimeException e) {
        // "action.undo" calls user code and might throw an unchecked exception
        // we catch the error here to gather information on where the problem occurred.
        actionStatus =
            new Status(
                IStatus.ERROR,
                EngineActivator.ID,
                NLS.bind(Messages.action_undo_error, action.getClass().getName()),
                e);
      } catch (LinkageError e) {
        // Catch linkage errors as these are generally recoverable but let other Errors propagate
        // (see bug 222001)
        actionStatus =
            new Status(
                IStatus.ERROR,
                EngineActivator.ID,
                NLS.bind(Messages.action_undo_error, action.getClass().getName()),
                e);
      }
      if (actionStatus != null && actionStatus.matches(IStatus.ERROR)) {
        MultiStatus result =
            new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null);
        result.add(
            new Status(
                IStatus.ERROR,
                EngineActivator.ID,
                session.getContextString(this, operand, action),
                null));
        result.merge(actionStatus);
      }
    }
    mergeStatus(
        status,
        touchpointCompleteOperand(profile, operand, operandParameters, new NullProgressMonitor()));
    mergeStatus(
        status, completeOperand(profile, operand, operandParameters, new NullProgressMonitor()));
    operandParameters = null;
  }
Exemple #23
0
  @Override
  public void run() {
    final ITextEditor editor = getTextEditor();
    final ITranslationUnit tu = getTranslationUnit(editor);
    if (tu == null) {
      return;
    }
    final ISelection selection = getTextEditor().getSelectionProvider().getSelection();
    if (selection.isEmpty() || !(selection instanceof ITextSelection)) {
      return;
    }
    if (!validateEditorInputState()) {
      return;
    }

    final MultiTextEdit[] holder = new MultiTextEdit[1];
    SharedASTJob job =
        new SharedASTJob(CEditorMessages.AddInclude_action, tu) {
          @Override
          public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
            if (ast == null) {
              return CUIPlugin.createErrorStatus(
                  NLS.bind(
                      CEditorMessages.AddInclude_ast_not_available, tu.getPath().toOSString()));
            }

            IIndex index =
                CCorePlugin.getIndexManager()
                    .getIndex(
                        tu.getCProject(),
                        IIndexManager.ADD_DEPENDENCIES
                            | IIndexManager.ADD_EXTENSION_FRAGMENTS_ADD_IMPORT);
            try {
              index.acquireReadLock();
              IncludeCreator creator = new IncludeCreator(tu, index, fAmbiguityResolver);
              holder[0] = creator.createInclude(ast, (ITextSelection) selection);
              return Status.OK_STATUS;
            } catch (InterruptedException e) {
              return Status.CANCEL_STATUS;
            } finally {
              index.releaseReadLock();
            }
          }
        };
    IStatus status = BusyCursorJobRunner.execute(job);
    if (status.isOK()) {
      MultiTextEdit edit = holder[0];
      if (edit.hasChildren()) {
        // Apply text edits.
        IEditorInput editorInput = editor.getEditorInput();
        IDocument document = editor.getDocumentProvider().getDocument(editorInput);
        IDocumentUndoManager manager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
        manager.beginCompoundChange();
        try {
          edit.apply(document);
        } catch (MalformedTreeException | BadLocationException e) {
          CUIPlugin.log(e);
        }
        manager.endCompoundChange();
      }
    } else if (status.matches(IStatus.ERROR)) {
      ErrorDialog.openError(
          editor.getEditorSite().getShell(),
          CEditorMessages.AddInclude_error_title,
          CEditorMessages.AddInclude_insertion_failed,
          status);
    }
  }
 @Test
 public void testSkipNonErrorStatusPredicateCancel() {
   when(status.matches(IStatus.CANCEL)).thenReturn(true);
   Predicate<IStatus> sut = new ErrorStatusOnlyPredicate();
   assertFalse(sut.apply(status));
 }
 protected void updateStatus(IStatus status) {
   setPageComplete(!status.matches(IStatus.ERROR));
   StatusUtils.applyToStatusLine(this, status);
 }
 @Test
 public void testSkipNonErrorStatusPredicateError() {
   when(status.matches(IStatus.ERROR)).thenReturn(true);
   Predicate<IStatus> sut = new ErrorStatusOnlyPredicate();
   assertTrue(sut.apply(status));
 }
 @Test
 public void testSkipNonErrorStatusPredicateWarning() {
   when(status.matches(IStatus.WARNING)).thenReturn(true);
   Predicate<IStatus> sut = new ErrorStatusOnlyPredicate();
   assertFalse(sut.apply(status));
 }