コード例 #1
0
  /**
   * Called when an IJavaElement changes. Used to reflect changes in the editor, which has a view
   * that is based on the <code>JavaModel</code>.
   *
   * @param event - The change that occurred to the <code>JavaModel</code>.
   */
  @SuppressWarnings("unchecked")
  public void elementChanged(ElementChangedEvent event) {
    try {
      /* Goes through these classes looking for any that are added, moved
       * or removed. Calls methods that updates the editor to reflect any
       * changes found.
       */
      for (Class type : map.keySet()) {
        List<IJavaElementDelta> added = findAddedElements(event.getDelta(), type);
        List<IJavaElementDelta> removed = findRemovedElements(event.getDelta(), type);
        List<IJavaElementDelta> changed = findChangedElements(event.getDelta(), type);
        HashMap<IJavaElement, IJavaElement> moved = extractMovedElements(added, removed);

        // ignore updating the editors if no changes occurred
        if (added.size() == 0 && removed.size() == 0 && moved.size() == 0 && changed.size() == 0) {
          continue;
        }

        List<DiagramEditor> editors = new ArrayList<DiagramEditor>(DiagramEditor.getEditors());

        // handle changes
        for (DiagramEditor editor : editors) {
          RootModel root = editor.getRootModel();

          // handle moves
          for (IJavaElement sourceElement : moved.keySet()) {
            IJavaElement targetElement = moved.get(sourceElement);
            map.get(sourceElement.getClass()).handleMove(root, sourceElement, targetElement);
          }

          // handle removes
          for (IJavaElementDelta removedElement : removed) {
            map.get(removedElement.getElement().getClass())
                .handleRemove(root, removedElement.getElement());
          }

          // handle adds
          for (IJavaElementDelta addedElement : added) {
            map.get(addedElement.getElement().getClass())
                .handleAdd(root, addedElement.getElement());
          }

          // handle changes (to modifiers, etc.)
          for (IJavaElementDelta changedElement : changed) {
            handleElementChange(changedElement);
          }

          editor.forceRefreshRelationships();
        }
      }
    } catch (Throwable t) {
      // TODO Incremental exploration throws Null Pointer.  Virtually unreproduceable.
      GreenException.critical(t);
    } finally {
      TypeRefactorHandler.REMOVED_TYPE = null;
    }
  }
コード例 #2
0
  /**
   * Updates the display when some change occurs to a Java element that doesn't involve removal,
   * addition, or movement.
   *
   * @param elementDelta - The delta of the element that changed.
   */
  private void handleElementChange(IJavaElementDelta elementDelta) {
    IJavaElement element = elementDelta.getElement();

    // update the modifiers of the element (if they changed)
    if ((elementDelta.getFlags() & IJavaElementDelta.F_MODIFIERS) != 0) {
      for (DiagramEditor editor : DiagramEditor.getEditors()) {
        RootPart rootEditPart = editor.getRootPart();
        RootModel root = (RootModel) rootEditPart.getModel();
        AbstractModel abstractModel = root.getModelFromElement(element);

        if (abstractModel != null) {
          if (abstractModel instanceof FieldModel) {
            FieldModel fModel = (FieldModel) abstractModel;
            FieldPart fEditPart = (FieldPart) rootEditPart.getPartFromModel(fModel);
            fEditPart.updateIcon();
          } else if (abstractModel instanceof MethodModel) {
            MethodModel mModel = (MethodModel) abstractModel;
            MethodPart mEditPart = (MethodPart) rootEditPart.getPartFromModel(mModel);
            mEditPart.updateIcon();
          }
        }
      }
    }
  }