/*
  * @see StructuredViewer#handleInvalidSelection(ISelection, ISelection)
  */
 protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) {
   // on change of input, try to keep selected methods stable by selecting a method with the same
   // signature: See #5466
   List oldSelections = SelectionUtil.toList(invalidSelection);
   List newSelections = SelectionUtil.toList(newSelection);
   if (!oldSelections.isEmpty()) {
     ArrayList newSelectionElements = new ArrayList(newSelections);
     try {
       Object[] currElements = getFilteredChildren(getInput());
       for (int i = 0; i < oldSelections.size(); i++) {
         Object curr = oldSelections.get(i);
         if (curr instanceof IMethod && !newSelections.contains(curr)) {
           IMethod method = (IMethod) curr;
           if (method.exists()) {
             IMethod similar = findSimilarMethod(method, currElements);
             if (similar != null) {
               newSelectionElements.add(similar);
             }
           }
         }
       }
       if (!newSelectionElements.isEmpty()) {
         newSelection = new StructuredSelection(newSelectionElements);
       } else if (currElements.length > 0) {
         newSelection = new StructuredSelection(currElements[0]);
       }
     } catch (ModelException e) {
       DLTKUIPlugin.log(e);
     }
   }
   setSelection(newSelection);
   updateSelection(newSelection);
 }
Example #2
0
 public static void logErrorMessage(String message, Throwable throwable) {
   DLTKUIPlugin.log(
       new Status(
           IStatus.ERROR,
           DLTKUIPlugin.PLUGIN_ID,
           IDLTKStatusConstants.INTERNAL_ERROR,
           message,
           throwable));
 }
Example #3
0
 public static void log(Throwable e) {
   DLTKUIPlugin.log(
       new Status(
           IStatus.ERROR,
           DLTKUIPlugin.PLUGIN_ID,
           IDLTKStatusConstants.INTERNAL_ERROR,
           DLTKUIMessages.ScriptPlugin_internal_error,
           e));
 }
Example #4
0
 public static void logErrorStatus(String message, IStatus status) {
   if (status == null) {
     DLTKUIPlugin.logErrorMessage(message);
     return;
   }
   MultiStatus multi =
       new MultiStatus(DLTKUIPlugin.PLUGIN_ID, IDLTKStatusConstants.INTERNAL_ERROR, message, null);
   multi.add(status);
   DLTKUIPlugin.log(multi);
 }
Example #5
0
  static void setReadOnly(IResource resource, boolean readOnly) {
    ResourceAttributes resourceAttributes = resource.getResourceAttributes();
    if (resourceAttributes == null) // not supported on this platform for this resource
    return;

    resourceAttributes.setReadOnly(readOnly);
    try {
      resource.setResourceAttributes(resourceAttributes);
    } catch (CoreException e) {
      DLTKUIPlugin.log(e);
    }
  }
Example #6
0
 /*
  * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
  */
 public void selectionChanged(IStructuredSelection selection) {
   if (ReorgUtils.containsOnlyProjects(selection.toList())) {
     setEnabled(createWorkbenchAction(selection).isEnabled());
     return;
   }
   try {
     setEnabled(RefactoringAvailabilityTester.isDeleteAvailable(selection.toArray()));
   } catch (CoreException e) {
     // no ui here - this happens on selection changes
     // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
     if (ScriptModelUtil.isExceptionToBeLogged(e)) DLTKUIPlugin.log(e);
     setEnabled(false);
   }
 }
Example #7
0
  /**
   * Returns the Script content assist history.
   *
   * @return the Script content assist history
   */
  public ContentAssistHistory getContentAssistHistory() {
    if (fContentAssistHistory == null) {
      try {
        fContentAssistHistory =
            ContentAssistHistory.load(
                getPluginPreferences(), PreferenceConstants.CODEASSIST_LRU_HISTORY);
      } catch (CoreException x) {
        DLTKUIPlugin.log(x);
      }
      if (fContentAssistHistory == null) {
        fContentAssistHistory = new ContentAssistHistory();
      }
    }

    return fContentAssistHistory;
  }
  public ISourceRange getNewSelectionRange(ISourceRange oldSourceRange, IType[] types) {
    try {
      if (types == null) types = getTypes();
      Integer[] offsetArray = createOffsetArray(types);
      if (offsetArray.length == 0) return oldSourceRange;
      Arrays.sort(offsetArray);
      Integer oldOffset = new Integer(oldSourceRange.getOffset());
      int index = Arrays.binarySearch(offsetArray, oldOffset);

      if (fIsGotoNext) return createNewSourceRange(getNextOffset(index, offsetArray, oldOffset));
      else return createNewSourceRange(getPreviousOffset(index, offsetArray, oldOffset));

    } catch (ModelException e) {
      DLTKUIPlugin.log(e); // dialog would be too heavy here
      return oldSourceRange;
    }
  }
  /*
   * (non-Javadoc) Method declared on IElementChangedListener.
   */
  public void elementChanged(final ElementChangedEvent event) {
    final ArrayList<Runnable> runnables = new ArrayList<Runnable>();
    try {
      // 58952 delete project does not update Package Explorer [package
      // explorer]
      // if the input to the viewer is deleted then refresh to avoid the
      // display of stale elements
      if (inputDeleted(runnables)) {
        return;
      }

      processDelta(event.getDelta(), runnables);
    } catch (ModelException e) {
      DLTKUIPlugin.log(e);
    } finally {
      executeRunnables(runnables);
    }
  }
 /**
  * Finds and returns the Script element selected in the given part.
  *
  * @param part the workbench part for which to find the selected Script element
  * @param selection the selection
  * @return the selected Script element
  */
 protected Object findSelectedModelElement(IWorkbenchPart part, ISelection selection) {
   try {
     if (isValidWorkbenchPart(part) && selection instanceof ITextSelection) {
       final IEditorPart editor = (IEditorPart) part;
       IModelElement[] elements =
           TextSelectionConverter.codeResolve(editor, (ITextSelection) selection);
       if (elements != null && elements.length > 0) {
         return elements.length == 1 ? elements[0] : (Object) new ModelElementArray(elements);
       }
     } else if (selection instanceof IStructuredSelection) {
       Object element = SelectionUtil.getSingleElement(selection);
       return findModelElement(element);
     }
   } catch (ModelException e) {
     DLTKUIPlugin.log(e);
   }
   return null;
 }
Example #11
0
 public static void warn(String message, Throwable throwable) {
   log(
       new Status(
           IStatus.WARNING, PLUGIN_ID, IDLTKStatusConstants.INTERNAL_ERROR, message, throwable));
 }