Exemplo n.º 1
0
 @Override
 public void createPartControl(Composite parent) {
   this.parent = parent;
   huiComposite = new HitroUIComposite(parent, false);
   try {
     // no validation here, so empty list passed
     huiComposite.createView(
         attachment.getEntity(),
         true,
         true,
         new String[] {},
         false,
         new ArrayList<String>(0),
         Activator.getDefault()
             .getPreferenceStore()
             .getBoolean(PreferenceConstants.USE_VALIDATION_GUI_HINTS));
   } catch (DBException e) {
     LOG.error("Error while creating editor", e); // $NON-NLS-1$
   }
   InputHelperFactory.setInputHelpers(
       HitroUtil.getInstance()
           .getTypeFactory()
           .getEntityType(attachment.getEntity().getEntityType()),
       huiComposite);
 }
Exemplo n.º 2
0
 /**
  * Creates an ext-id for an attachment
  *
  * @param attachment an attachment of a tree-element
  * @return ext-id for the attachment
  */
 public static String createExtId(Attachment attachment) {
   String extId = attachment.getExtId();
   if (extId == null || extId.isEmpty()) {
     extId = attachment.getEntity().getId();
   }
   return extId;
 }
Exemplo n.º 3
0
 /** @param attachment */
 public static String createZipFileName(Attachment attachment) {
   StringBuilder sb = new StringBuilder();
   sb.append(VeriniceArchive.FILES).append("/");
   sb.append(attachment.getDbId()).append("-");
   // avoid problems with non-ASCII file names
   String fileName = attachment.getFileName();
   fileName = ExportFactory.replaceNonAsciiChars(fileName);
   sb.append(fileName);
   return sb.toString().replaceAll(" ", "_");
 }
Exemplo n.º 4
0
  /**
   * Creates the verinice archive after createXmlData() was called.
   *
   * @return the verinice archive as byte[]
   * @throws CommandException
   */
  private byte[] createVeriniceArchive() throws CommandException {
    try {
      final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
      final ZipOutputStream zipOut = new ZipOutputStream(byteOut);

      ExportFactory.createZipEntry(zipOut, VeriniceArchive.VERINICE_XML, xmlData);
      if (isRiskAnalysis()) {
        ExportFactory.createZipEntry(zipOut, VeriniceArchive.RISK_XML, xmlDataRiskAnalysis);
      }
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.DATA_XSD, StreamFactory.getDataXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.MAPPING_XSD, StreamFactory.getMappingXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.SYNC_XSD, StreamFactory.getSyncXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.RISK_XSD, StreamFactory.getRiskXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.README_TXT, StreamFactory.getReadmeAsStream());

      for (final Attachment attachment : getAttachmentSet()) {
        LoadAttachmentFile command = new LoadAttachmentFile(attachment.getDbId(), true);
        command = getCommandService().executeCommand(command);
        if (command.getAttachmentFile() != null
            && command.getAttachmentFile().getFileData() != null) {
          ExportFactory.createZipEntry(
              zipOut,
              ExportFactory.createZipFileName(attachment),
              command.getAttachmentFile().getFileData());
        }
        command.setAttachmentFile(null);
      }

      zipOut.close();
      byteOut.close();
      return byteOut.toByteArray();
    } catch (final IOException e) {
      getLog().error("Error while creating zip output stream", e);
      throw new RuntimeCommandException(e);
    }
  }
  protected Image getImage(Object element) {
    if (!(element instanceof Attachment)) {
      return null;
    }
    Attachment attachment = (Attachment) element;

    Image thumb = null;
    if (Arrays.asList(Attachment.getImageMimeTypes()).contains(attachment.getMimeType())) {
      Element cacheElement = getCache().get(attachment.getDbId());
      if (cacheElement != null) {
        // != is correct here
        if (cacheElement.getObjectValue() != EMPTY_CACHE_ELEMENT) {
          ImageData imageData = (ImageData) cacheElement.getObjectValue();
          thumb = new Image(FileView.getDisplay(), imageData);
        }
      } else {
        byte[] fileData = loadFileData(attachment);
        thumb = createImage(fileData);
        if (thumb != null) {
          getCache().put(new Element(attachment.getDbId(), thumb.getImageData()));
        } else {
          getCache().put(new Element(attachment.getDbId(), EMPTY_CACHE_ELEMENT));
        }
      }
    }
    return thumb;
  }
Exemplo n.º 6
0
 @Override
 public void doSave(IProgressMonitor monitor) {
   monitor.beginTask(Messages.AttachmentEditor_1, IProgressMonitor.UNKNOWN);
   boolean isNew = attachment.getDbId() == null;
   Set<INoteChangedListener> listener = attachment.getListener();
   SaveNote command = new SaveNote(attachment);
   try {
     command = getCommandService().executeCommand(command);
     attachment = (Attachment) command.getAddition();
     huiComposite.dispose();
     huiComposite = new HitroUIComposite(parent, false);
     huiComposite.createView(
         attachment.getEntity(),
         true,
         true,
         new String[] {},
         false,
         ServiceFactory.lookupValidationService()
             .getPropertyTypesToValidate(attachment.getEntity(), attachment.getDbId()),
         Activator.getDefault()
             .getPreferenceStore()
             .getBoolean(PreferenceConstants.USE_VALIDATION_GUI_HINTS));
     parent.layout();
     // file-data is immutable, just save new file-data
     if (isNew) {
       AttachmentFileCreationFactory.createAttachmentFile(
           attachment, FileUtils.readFileToByteArray(new File(attachment.getFilePath())));
     }
   } catch (Exception e) {
     LOG.error("Error while saving file", e); // $NON-NLS-1$
     ExceptionUtil.log(e, Messages.AttachmentEditor_3);
   }
   monitor.done();
   attachment.getListener().addAll(listener);
   isModelModified = false;
   firePropertyChange(IEditorPart.PROP_DIRTY);
   attachment.getEntity().addChangeListener(this.modelListener);
   setPartName(attachment.getTitel());
   attachment.fireChange();
 }