Ejemplo n.º 1
0
 @Override
 public String getColumnText(Object element, int columnIndex) {
   try {
     if (element instanceof PlaceHolder) {
       if (columnIndex == 1) {
         PlaceHolder ph = (PlaceHolder) element;
         return ph.getTitle();
       }
       return ""; //$NON-NLS-1$
     }
     ReportTemplateMetaData data = (ReportTemplateMetaData) element;
     switch (columnIndex) {
       case 0:
         return data.getOutputname(); // $NON-NLS-1$
       case 1:
         StringBuilder sb = new StringBuilder();
         OutputFormat[] formats = data.getOutputFormats();
         for (int i = 0; i < formats.length; i++) {
           sb.append(formats[i]);
           if (!(i == formats.length - 1)) {
             sb.append(", ");
           }
         }
         return sb.toString(); // $NON-NLS-1$
       case 2:
         return data.getFilename(); // $NON-NLS-1$
       default:
         return null;
     }
   } catch (Exception e) {
     LOG.error("Error while getting column text", e); // $NON-NLS-1$
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 2
0
    /*
     * (non-Javadoc)
     *
     * @see
     * org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface
     * .viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(Viewer viewer, Object e1, Object e2) {
      ReportTemplateMetaData data1 = (ReportTemplateMetaData) e1;
      ReportTemplateMetaData data2 = (ReportTemplateMetaData) e2;
      int rc = 0;
      if (e1 == null) {
        if (e2 != null) {
          rc = 1;
        }
      } else if (e2 == null) {
        rc = -1;
      } else {
        // e1 and e2 != null
        switch (propertyIndex) {
          case 0:
            rc = comporeToLowerCase(data1.getDecoratedOutputname(), data2.getDecoratedOutputname());
            break;
          case 1:
            // implement a sorted list here that needs to be compared
            String s1 = getSortedOutputFormatsString(data1.getOutputFormats());
            String s2 = getSortedOutputFormatsString(data2.getOutputFormats());
            if (s1 != null && s2 != null) {
              rc = s1.compareTo(s2);
            }
            break;
          case 2:
            rc = comporeToLowerCase(data1.getFilename(), data2.getFilename());
            break;
          default:
            rc = 0;
        }
      }

      // If descending order, flip the direction
      if (direction == DESCENDING) {
        rc = -rc;
      }
      return rc;
    }