示例#1
0
  public void fileRenamed(FileRenameEvent fe) {
    FileObject fo = fe.getFile();
    if (FileUtil.isParentOf(root, fo) && fo.isFolder()) {
      String rp = FileUtil.getRelativePath(root, fo.getParent());
      String oldPath = rp + (rp.length() == 0 ? "" : "/") + fe.getName() + fe.getExt(); // NOI18N

      boolean visible = VisibilityQuery.getDefault().isVisible(fo);
      boolean doUpdate = false;

      // Find all entries which have to be updated
      ArrayList needsUpdate = new ArrayList();
      for (Iterator it = names2nodes.keySet().iterator(); it.hasNext(); ) {
        String p = (String) it.next();
        if (p.startsWith(oldPath)) {
          if (visible) {
            needsUpdate.add(p);
          } else {
            names2nodes.remove(p);
            doUpdate = true;
          }
        }
      }

      // If the node does not exists then there might have been update
      // from ignored to non ignored
      if (get(fo) == null && visible) {
        cleanEmptyKeys(fo);
        findNonExcludedPackages(fo);
        doUpdate = true; // force refresh
      }

      int oldPathLen = oldPath.length();
      String newPath = FileUtil.getRelativePath(root, fo);
      for (Iterator it = needsUpdate.iterator(); it.hasNext(); ) {
        String p = (String) it.next();
        StringBuffer np = new StringBuffer(p);
        np.replace(0, oldPathLen, newPath);
        PackageNode n = updatePath(p, np.toString()); // Replace entries in cache
        if (n != null) {
          n.updateDisplayName(); // Update nodes
        }
      }

      if (needsUpdate.size() > 1 || doUpdate) {
        // Sorting might change
        refreshKeys();
      }
    }
    /*
    else if ( FileUtil.isParentOf( root, fo ) && fo.isFolder() ) {
        FileObject parent = fo.getParent();
        PackageNode n = get( parent );
        if ( n != null && VisibilityQuery.getDefault().isVisible( parent ) ) {
            n.updateChildren();
        }

    }
    */

  }
  public void preprocessPackageNode(PackageNode node) {
    super.preprocessPackageNode(node);

    packages.add(node);

    getChartData(node.getClasses().size())[CLASSES_PER_PACKAGE]++;
    getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_PACKAGE]++;
    getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_PACKAGE]++;
  }
  public void visitOutboundPackageNode(PackageNode node) {
    if (!getCoverage().contains(node)) {
      getSelectedNodes().add(node);

      Node copy = getFactory().createPackage(node.getName(), node.isConfirmed());
      getCopiedNodes().add(copy);
      currentNode.addDependency(copy);
    }
  }
  /**
   * Implements the getConnectionPoint method in Connector interface.
   *
   * @param wayPoint the way point to be connected
   * @return the target connection point
   * @throws IllegalArgumentException if given wayPoint is null
   */
  public Point getConnectionPoint(Point wayPoint) {
    Util.checkNotNull(wayPoint, "wayPoint");

    // Get the top rectangle
    Point position = parent.getLocation();
    position.x += parent.getSelectionBound().x;
    position.y += parent.getSelectionBound().y;
    Dimension size = new Dimension();
    Dimension compartmentSize = null;
    if (parent.getStereotypeCompartment().isVisible()) {
      compartmentSize = parent.getStereotypeCompartment().getPreferredSize();
      Util.combineSize(size, compartmentSize, true);
    }
    compartmentSize = parent.getNameCompartment().getSize();
    if (parent.getNamespaceCompartment().isVisible()) {
      Util.combineSize(size, compartmentSize, true);
      compartmentSize = parent.getNamespaceCompartment().getSize();
      Util.combineSize(size, compartmentSize, false);
    } else {
      Util.combineSize(size, compartmentSize, false);
    }

    if (wayPoint.x < position.x + size.width && wayPoint.y < position.y + size.height) {
      // Connect to the top rectangle
      Rectangle bound = new Rectangle(position, size);
      return new RectangleConnector(bound).getConnectionPoint(wayPoint);
    }

    // Connect to the bottom rectangle
    position.y += size.height;
    size.width = parent.getSelectionBound().width;
    size.height = parent.getSelectionBound().height - size.height;
    Rectangle bound = new Rectangle(position, size);
    return new RectangleConnector(bound).getConnectionPoint(wayPoint);
  }
示例#5
0
 public void fileDataCreated(FileEvent fe) {
   FileObject fo = fe.getFile();
   if (FileUtil.isParentOf(root, fo) && isVisible(root, fo)) {
     FileObject parent = fo.getParent();
     if (!VisibilityQuery.getDefault().isVisible(parent)) {
       return; // Adding file into ignored directory
     }
     PackageNode n = get(parent);
     if (n == null && !contains(parent)) {
       add(parent, false);
       refreshKeys();
     } else if (n != null) {
       n.updateChildren();
     }
   }
 }
示例#6
0
  public void fileDeleted(FileEvent fe) {
    FileObject fo = fe.getFile();
    if (FileUtil.isParentOf(root, fo) && isVisible(root, fo)) {
      if (fo.isFolder() || get(fo) != null) {
        removeSubTree(fo);
        // Now add the parent if necessary
        FileObject parent = fo.getParent();
        if ((FileUtil.isParentOf(root, parent) || root.equals(parent))
            && get(parent) == null
            && parent.isValid()) {
          // Candidate for adding
          if (!toBeRemoved(parent)) {
            add(parent, true);
          }
        }
        refreshKeysAsync();
      } else {
        FileObject parent = fo.getParent();
        final PackageNode n = get(parent);
        if (n != null) {
          // #61027: workaround to a deadlock when the package is being changed from non-leaf to
          // leaf:
          boolean leaf = n.isLeaf();
          DataFolder df = n.getDataFolder();
          boolean empty = n.isEmpty(df);

          if (leaf != empty) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    n.updateChildren();
                  }
                });
          } else {
            n.updateChildren();
          }
        }
        // If the parent folder only contains folders remove it
        if (toBeRemoved(parent)) {
          remove(parent);
          refreshKeysAsync();
        }
      }
    }
  }
  public void testFeatureFeature() {
    a.addDependency(b);
    a.addDependency(b_B);
    a.addDependency(b_B_b);
    a_A.addDependency(b);
    a_A.addDependency(b_B);
    a_A.addDependency(b_B_b);
    a_A_a.addDependency(b);
    a_A_a.addDependency(b_B);
    a_A_a.addDependency(b_B_b);

    Visitor visitor = new LinkMinimizer();
    visitor.traverseNodes(factory.getPackages().values());

    assertEquals("a outbound", 0, a.getOutboundDependencies().size());
    assertEquals("a inbound", 0, a.getInboundDependencies().size());
    assertEquals("a_A outbound", 0, a_A.getOutboundDependencies().size());
    assertEquals("a_A inbound", 0, a_A.getInboundDependencies().size());
    assertEquals("a_A_a outbound", 1, a_A_a.getOutboundDependencies().size());
    assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b));
    assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies().size());
    assertEquals("b outbound", 0, b.getOutboundDependencies().size());
    assertEquals("b inbound", 0, b.getInboundDependencies().size());
    assertEquals("b_B outbound", 0, b_B.getOutboundDependencies().size());
    assertEquals("b_B inbound", 0, b_B.getInboundDependencies().size());
    assertEquals("b_B_b outbound", 0, b_B_b.getOutboundDependencies().size());
    assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies().size());
    assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a));
  }
示例#8
0
  /** Finds all empty parents of given package and deletes them */
  private void cleanEmptyKeys(FileObject fo) {
    FileObject parent = fo.getParent();

    // Special case for default package
    if (root.equals(parent)) {
      PackageNode n = get(parent);
      // the default package is considered empty if it only contains folders,
      // regardless of the contents of these folders (empty or not)
      if (n != null && PackageDisplayUtils.isEmpty(root, false)) {
        remove(root);
      }
      return;
    }

    while (FileUtil.isParentOf(root, parent)) {
      PackageNode n = get(parent);
      if (n != null && n.isLeaf()) {
        remove(parent);
      }
      parent = parent.getParent();
    }
  }
示例#9
0
  private void renderPackage(PackageNode pnode) {

    String str;

    // rootNode
    if (pnode.getParent() == null) {
      str = "Aggregate";
    } else { // all the other nodes
      str = pnode.getPackageName();
      pnode.getParent().addNumberOfViolation(pnode.getNumberOfViolations());
    }

    packageBuf.insert(
        length,
        "<tr><td><b>"
            + str
            + "</b></td>"
            + " <td>-</td>"
            + " <td>"
            + pnode.getNumberOfViolations()
            + "</td>"
            + "</tr>"
            + PMD.EOL);
  }
  /*
   * @see
   * org.openide.util.actions.NodeAction#performAction(org.openide.nodes.Node[])
   */
  @Override
  protected void performAction(Node[] activatedNodes) {
    final List<Package> updateList = new ArrayList<Package>();
    Node node2 = null;
    for (final Node node : activatedNodes)
      if (node instanceof PackageNode) {
        final Package pkg = (Package) ((PackageNode) node).getLookup().lookup(Package.class);
        if (node2 == null) node2 = node.getParentNode();
        updateList.add(pkg);
      }
    updatePackages(node2, updateList);
    updateList.remove(updateList);
    for (Node node : activatedNodes)
      while (node != null) {
        if (node instanceof PackageNode) ((PackageNode) node).refresh();

        node = node.getParentNode();
      }
  }
  static StyledString getStyledLabelFor(Node n) {
    // TODO: it would be much better to render types
    //      from the tree nodes instead of from the
    //      model nodes

    if (n instanceof Tree.TypeParameterDeclaration) {
      Tree.TypeParameterDeclaration ac = (Tree.TypeParameterDeclaration) n;
      return new StyledString(name(ac.getIdentifier()));
    }
    if (n instanceof Tree.AnyClass) {
      Tree.AnyClass ac = (Tree.AnyClass) n;
      StyledString label = new StyledString("class ", KW_STYLER);
      label.append(name(ac.getIdentifier()), TYPE_ID_STYLER);
      parameters(ac.getTypeParameterList(), label);
      parameters(ac.getParameterList(), label);
      return label;
    } else if (n instanceof Tree.AnyInterface) {
      Tree.AnyInterface ai = (Tree.AnyInterface) n;
      StyledString label = new StyledString("interface ", KW_STYLER);
      label.append(name(ai.getIdentifier()), TYPE_ID_STYLER);
      parameters(ai.getTypeParameterList(), label);
      return label;
    } else if (n instanceof Tree.ObjectDefinition) {
      Tree.ObjectDefinition ai = (Tree.ObjectDefinition) n;
      return new StyledString("object ", KW_STYLER).append(name(ai.getIdentifier()), ID_STYLER);
    } else if (n instanceof Tree.AttributeSetterDefinition) {
      Tree.AttributeSetterDefinition ai = (Tree.AttributeSetterDefinition) n;
      return new StyledString("assign ", KW_STYLER).append(name(ai.getIdentifier()), ID_STYLER);
    } else if (n instanceof Tree.TypedDeclaration) {
      Tree.TypedDeclaration td = (Tree.TypedDeclaration) n;
      String type;
      Styler styler;
      if (td.getType() instanceof Tree.VoidModifier) {
        type = "void";
        styler = KW_STYLER;
      } else {
        type = type(td.getType());
        styler = TYPE_STYLER;
      }
      StyledString label = new StyledString(type, styler);
      label.append(" ").append(name(td.getIdentifier()), ID_STYLER);
      if (n instanceof Tree.AnyMethod) {
        Tree.AnyMethod am = (Tree.AnyMethod) n;
        parameters(am.getTypeParameterList(), label);
        for (Tree.ParameterList pl : am.getParameterLists()) {
          parameters(pl, label);
        }
      }
      return label;
    } else if (n instanceof Tree.CompilationUnit) {
      Tree.CompilationUnit ai = (Tree.CompilationUnit) n;
      return new StyledString(ai.getUnit().getFilename());
    } else if (n instanceof Tree.ImportList) {
      return new StyledString("imports");
    } else if (n instanceof Tree.Import) {
      Tree.Import ai = (Tree.Import) n;
      if (ai.getImportPath() != null && !ai.getImportPath().getIdentifiers().isEmpty()) {
        return new StyledString(toPath(ai), QUALIFIER_STYLER);
      }
    } else if (n instanceof PackageNode) {
      PackageNode pn = (PackageNode) n;
      if (pn.getPackageName().isEmpty()) {
        return new StyledString("default package");
      } else {
        return new StyledString(pn.getPackageName(), QUALIFIER_STYLER);
      }
    }

    return new StyledString("<something>");
  }
 public void visitPackage(PackageNode node) {
   if (node != null) {
     visitAnnotations(node);
     node.visit(this);
   }
 }
 public void visitPackageNode(PackageNode node) {
   currentNode = getFactory().createPackage(node.getName(), node.isConfirmed());
 }