DuplicateImage.java in stead of DuplicateFileDocument.java

1
We want to copy a image. In commomcommunity widget there is a duplicatefiledocument.java. We now that we can use this for duplicating an image. But we need to change a few things. What do we have to change in de the java to fix this. Below the java: DUPLICATIEFILEDOCUMENT.JAVA import communitycommons.Misc; /** * Clones the contents of one file document into another. * - fileToClone : the source file * - cloneTarget : an initialized file document, in which the file will be stored. Returns true if copied, returns file if the source had no contents, throws exception in any other case. Pre condition: HasContents of the 'fileToClone' need to be set to true, otherwise the action will not copy anything. */ public class DuplicateFileDocument extends UserAction<boolean> { private IMendixObject _fileToClone; private system.proxies.FileDocument fileToClone; private IMendixObject _cloneTarget; private system.proxies.FileDocument cloneTarget; public DuplicateFileDocument(IMendixObject fileToClone, IMendixObject cloneTarget) { super(); this.fileToClone = fileToClone; this.cloneTarget = cloneTarget; } @Override public Boolean executeAction() throws Exception { this.fileToClone = _fileToClone == null ? null : system.proxies.FileDocument.initialize(this.getContext(), _fileToClone); this.cloneTarget = __cloneTarget == null ? null : system.proxies.FileDocument.initialize(this.getContext(), __cloneTarget); // BEGIN USER CODE return Misc.duplicateFileDocument(this.getContext(), __fileToClone, __cloneTarget); // END USER CODE } /** Returns a string representation of this action */ @Override public String toString() { return "DuplicateFileDocument"; } // BEGIN EXTRA CODE // END EXTRA CODE } THE EMPTY DUPLICATEIMAGE.JAVA // This file was generated by Mendix Business Modeler 2.5. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package communitycommons.actions; import com.mendix.systemwideinterfaces.core.UserAction; import com.mendix.systemwideinterfaces.core.IMendixObject; /** */ public class DuplicateImage extends UserAction<boolean> { private IMendixObject _fileToClone; private system.proxies.Image fileToClone; private IMendixObject _cloneTarget; private system.proxies.Image cloneTarget; public DuplicateImage(IMendixObject fileToClone, IMendixObject cloneTarget) { super(); this.__fileToClone = fileToClone; this.__cloneTarget = cloneTarget; } @Override public Boolean executeAction() throws Exception { this.fileToClone = __fileToClone == null ? null : system.proxies.Image.initialize(this.getContext(), __fileToClone); this.cloneTarget = __cloneTarget == null ? null : system.proxies.Image.initialize(this.getContext(), __cloneTarget); // BEGIN USER CODE return true; // END USER CODE } /** * Returns a string representation of this action */ @Override public String toString() { return "DuplicateImage"; } // BEGIN EXTRA CODE // END EXTRA CODE }
asked
1 answers
1

Oplossing gevonden!

a. Zet de CommunityCommons in je project uit de app store.

b. Creeer hierna een java actie die heet “DuplicateImage” in de map ‘Misc’ van de module ‘CommunityCommons’ in de modeler . Deze actie moet twee inputparameters krijgen:

  1. Name: ‘fileToClone’ Type: ‘System.Image’

  2. Name: ‘cloneTarget’ Type: ‘System.Image’

c. Deploy je project en kopieer de meegeleverde javasource in de map ‘javasource/comminutycommons/actions’ (hier zou al een lege actie moeten staan met dezelfde naam)

d. Open hierna de javasource ‘Misc.java’ in een textverwerker uit de map ‘javasource/comminutycommons’. Kopieer in deze javasource de volgende java functie

public static Boolean duplicateImage(IContext context, IMendixObject toClone, IMendixObject target) throws Exception { if (toClone == null || target == null) throw new Exception("No file to clone or to clone into provided");

    MendixBoolean hasContents = (MendixBoolean) toClone.getMember(context, FileDocument.MemberNames.HasContents.toString());
    if (!hasContents.getValue(context))
        return false;

    InputStream inputStream = Core.getImage(context, toClone, false);

    Core.storeImageDocumentContent(context, target, inputStream, 200, 200);

    return true;
}

Zet deze code tussen twee (willekeurige) andere functies. Bijvoorbeeld op regel 72 tussen de functies ‘duplicateFileDocument’ en ‘storeURLToFileDocument’.

e. De aangemaakte javaactie in de modeler kan je nu twee image objecten meegeven een te kopieeren image en een target image. Test dit wel goed, aangezien ik niet de tijd heb om dit op dit moment te testen.

answered