Example #1
0
 public Object parse(String sValue) throws NuclosFileImportException {
   try {
     if (!StringUtils.looksEmpty(sValue)) {
       return parserfactory.parse(this.cls, sValue, this.sFormat);
     } else {
       return null;
     }
   } catch (CommonParseException ex) {
     throw new NuclosFileImportException(
         StringUtils.getParameterizedExceptionMessage(
             "import.structure.exception", this.getFieldName()),
         ex);
   }
 }
Example #2
0
 public boolean isReferencing() {
   return !StringUtils.isNullOrEmpty(foreignentity);
 }
Example #3
0
  @Override
  public Component getTreeCellRendererComponent(
      JTree tree,
      Object oValue,
      boolean bSelected,
      boolean bExpanded,
      boolean bLeaf,
      int iRow,
      boolean bHasFocus) {

    final JLabel lbl =
        (JLabel)
            super.getTreeCellRendererComponent(
                tree, oValue, bSelected, bExpanded, bLeaf, iRow, bHasFocus);

    String tmp = lbl.getText();

    final List<PaintImage> images = new LinkedList<PaintImage>();

    int idx = -1;
    int spaceX = SwingUtilities.computeStringWidth(lbl.getFontMetrics(lbl.getFont()), " ");

    while ((idx = tmp.indexOf("[$" + CollectableFieldFormat.class.getName() + ",")) != -1) {
      int formatEnd = tmp.indexOf("$]");
      String format = tmp.substring(idx, formatEnd);

      String[] formatDef = format.split(",");
      try {
        CollectableFieldFormat clctformat =
            CollectableFieldFormat.getInstance(Class.forName(formatDef[1]));

        int x =
            SwingUtilities.computeStringWidth(
                lbl.getFontMetrics(lbl.getFont()), tmp.substring(0, idx));

        NuclosImage img = (NuclosImage) clctformat.parse(null, formatDef[3]);

        String tmp1 = tmp.substring(0, idx);
        for (int i = 0; i < img.getWidth() / spaceX; i++) {
          tmp1 += " ";
        }
        tmp1 += tmp.substring(formatEnd + 2);
        tmp = tmp1;

        images.add(new PaintImage(x, img));
      } catch (CollectableFieldFormatException e) {
        LOG.error("format exception at " + formatDef[1], e);
      } catch (ClassNotFoundException e) {
        LOG.error("class not found for " + formatDef[1], e);
      }
    }

    final ExplorerNode<?> explorernode = (ExplorerNode<?>) oValue;

    DefaultTreeCellRenderer lbComp =
        new DefaultTreeCellRenderer() {

          private static final long serialVersionUID = 5423600039963175923L;

          public void paintComponent(java.awt.Graphics g) {
            super.paintComponent(g);

            Graphics2D g2d = (Graphics2D) g;
            for (PaintImage paintImage : images) {
              g2d.drawImage(
                  new ImageIcon(paintImage.image.getContent()).getImage(),
                  getIcon().getIconWidth() + getIconTextGap() + paintImage.x,
                  1,
                  null);
            }
          };
        };

    JComponent result =
        (JComponent)
            lbComp.getTreeCellRendererComponent(
                tree, oValue, bSelected, bExpanded, bLeaf, iRow, bHasFocus);

    lbComp.setText(tmp);

    // set tooltip text:
    final String sDescription =
        StringUtils.nullIfEmpty(explorernode.getTreeNode().getDescription());
    lbComp.setToolTipText(sDescription);

    // set icon:
    final Icon icon = explorernode.getIcon();
    // if (icon != null) {
    lbComp.setIcon(icon);
    // }

    if (explorernode instanceof GenericObjectExplorerNode) {
      final Icon iconRelation = ((GenericObjectExplorerNode) explorernode).getRelationIcon();
      if (iconRelation != null) {
        lbComp.setIcon(new CompositeIcon(iconRelation, icon));

        // result = new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 0));
        // result.add(new JLabel(iconRelation));
        // result.add(lbl);
        // result.setOpaque(false);
      }
    }

    return result;
  }