private void doSaveImage(final String diagramFileString, BpmnMemoryModel model) {
    boolean saveImage =
        PreferencesUtil.getBooleanPreference(Preferences.SAVE_IMAGE, ActivitiPlugin.getDefault());
    if (saveImage) {
      List<String> languages =
          PreferencesUtil.getStringArray(
              Preferences.ACTIVITI_LANGUAGES, ActivitiPlugin.getDefault());
      if (languages != null && languages.size() > 0) {

        for (String language : languages) {
          for (Process process : model.getBpmnModel().getProcesses()) {
            fillContainerWithLanguage(process, language);
          }

          ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
          InputStream imageStream =
              processDiagramGenerator.generatePngDiagram(model.getBpmnModel());

          if (imageStream != null) {
            String imageFileName = null;
            if (diagramFileString.endsWith(".bpmn20.xml")) {
              imageFileName =
                  diagramFileString.substring(0, diagramFileString.length() - 11)
                      + "_"
                      + language
                      + ".png";
            } else {
              imageFileName =
                  diagramFileString.substring(0, diagramFileString.lastIndexOf("."))
                      + "_"
                      + language
                      + ".png";
            }
            File imageFile = new File(imageFileName);
            FileOutputStream outStream = null;
            ByteArrayOutputStream baos = null;
            try {
              outStream = new FileOutputStream(imageFile);
              baos = new ByteArrayOutputStream();
              IOUtils.copy(imageStream, baos);
              baos.writeTo(outStream);

            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              if (outStream != null) {
                IOUtils.closeQuietly(outStream);
              }
              if (baos != null) {
                IOUtils.closeQuietly(baos);
              }
            }
          }
        }

      } else {
        marshallImage(model, diagramFileString);
      }
    }
  }
 public void addOverlay(final GC imageGC, String modelFileName, BpmnMemoryModel model) {
   if (PreferencesUtil.getBooleanPreference(
       Preferences.SAVE_IMAGE_ADD_OVERLAY, ActivitiPlugin.getDefault())) {
     final ImageOverlayCreator creator = new ImageOverlayCreator(imageGC);
     creator.addOverlay(modelFileName, model);
   }
 }
  @Override
  protected void setInput(IEditorInput input) {
    super.setInput(input);

    final ActivitiDiagramEditorInput adei = (ActivitiDiagramEditorInput) input;
    final IFile dataFile = adei.getDataFile();

    final BpmnMemoryModel model =
        new BpmnMemoryModel(getDiagramTypeProvider().getFeatureProvider(), dataFile);
    ModelHandler.addModel(EcoreUtil.getURI(getDiagramTypeProvider().getDiagram()), model);

    String filePath = dataFile.getLocationURI().getPath();
    File bpmnFile = new File(filePath);
    try {
      if (bpmnFile.exists() == false) {
        model.setBpmnModel(new BpmnModel());
        model.addMainProcess();
        bpmnFile.createNewFile();
        dataFile.refreshLocal(IResource.DEPTH_INFINITE, null);
      } else {
        FileInputStream fileStream = new FileInputStream(bpmnFile);
        XMLInputFactory xif = XMLInputFactory.newInstance();
        InputStreamReader in = new InputStreamReader(fileStream, "UTF-8");
        XMLStreamReader xtr = xif.createXMLStreamReader(in);
        BpmnXMLConverter bpmnConverter = new BpmnXMLConverter();
        bpmnConverter.setUserTaskFormTypes(
            PreferencesUtil.getStringArray(
                Preferences.ALFRESCO_FORMTYPES_USERTASK, ActivitiPlugin.getDefault()));
        bpmnConverter.setStartEventFormTypes(
            PreferencesUtil.getStringArray(
                Preferences.ALFRESCO_FORMTYPES_STARTEVENT, ActivitiPlugin.getDefault()));
        BpmnModel bpmnModel = null;
        try {
          bpmnModel = bpmnConverter.convertToBpmnModel(xtr);
        } catch (Exception e) {
          bpmnModel = new BpmnModel();
        }
        model.setBpmnModel(bpmnModel);

        if (bpmnModel.getLocationMap().size() == 0) {
          BpmnAutoLayout layout = new BpmnAutoLayout(bpmnModel);
          layout.execute();
        }

        BasicCommandStack basicCommandStack =
            (BasicCommandStack) getEditingDomain().getCommandStack();

        if (input instanceof DiagramEditorInput) {

          basicCommandStack.execute(
              new RecordingCommand(getEditingDomain()) {

                @Override
                protected void doExecute() {
                  importDiagram(model);
                }
              });
        }
        basicCommandStack.saveIsDone();
        basicCommandStack.flush();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }