use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.
the class JSSolutionModel method getMedia.
/**
* Gets the specified media object; can be assigned to a button/label.
*
* @sample
* var myMedia = solutionModel.getMedia('button01.gif')
* //now set the imageMedia property of your label or button
* //myButton.imageMedia = myMedia
* // OR
* //myLabel.imageMedia = myMedia
*
* @param name the specified name of the media object
*
* @return a JSMedia element
*/
@JSFunction
public JSMedia getMedia(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
Media media = fs.getMedia(name);
if (media != null) {
return new JSMedia(media, application.getFlattenedSolution(), false);
}
return null;
}
use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.
the class JSSolutionModel method removeMedia.
/**
* Removes the media item specified by name.
*
* @sample
* var bytes1 = plugins.file.readFile('D:/Imgs/image1.png');
* var image1 = solutionModel.newMedia('image1.png', bytes1);
* var bytes2 = plugins.file.readFile('D:/Imgs/image2.jpg');
* var image2 = solutionModel.newMedia('image2.jpg',bytes2);
* var bytes3 = plugins.file.readFile('D:/Imgs/image3.jpg');
* var image3 = solutionModel.newMedia('image3.jpg',bytes3);
*
* var f = solutionModel.newForm("newForm",databaseManager.getDataSource('example_data', 'orders'),null,false,500,350);
* var l = f.newLabel('', 20, 70, 300, 200);
* l.imageMedia = image1;
* l.borderType = solutionModel.createLineBorder(4,'#ff0000');
* forms["newForm"].controller.show();
*
* var status = solutionModel.removeMedia('image1.jpg');
* if (status) application.output("image1.png has been removed");
* else application.output("image1.png has not been removed");
*
* var mediaList = solutionModel.getMediaList();
* for (var i = 0; i < mediaList.length; i++) {
* application.output(mediaList[i].getName() + ":" + mediaList[i].mimeType);
* }
*
* @param name the name of the media item to be removed
*
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeMedia(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
Media mediaItem = fs.getMedia(name);
if (mediaItem != null) {
fs.deletePersistCopy(mediaItem, false);
return true;
}
return false;
}
use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.
the class JSSolutionModel method getMediaList.
/**
* Gets the list of all media objects.
*
* @sample
* var mediaList = solutionModel.getMediaList();
* if (mediaList.length != 0 && mediaList != null) {
* for (var x in mediaList) {
* application.output(mediaList[x]);
* }
* }
*
* @return a list with all the media objects.
*/
@JSFunction
public JSMedia[] getMediaList() {
FlattenedSolution fs = application.getFlattenedSolution();
ArrayList<JSMedia> lst = new ArrayList<JSMedia>();
Iterator<Media> media = fs.getMedias(true);
while (media.hasNext()) {
lst.add(new JSMedia(media.next(), application.getFlattenedSolution(), false));
}
return lst.toArray(new JSMedia[lst.size()]);
}
use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.
the class JSSolutionModel method newMedia.
/**
* Creates a new media object that can be assigned to a label or a button.
*
* @sample
* var myMedia = solutionModel.newMedia('button01.gif',bytes)
* //now set the imageMedia property of your label or button
* //myButton.imageMedia = myMedia
* // OR
* //myLabel.imageMedia = myMedia
*
* @param name The name of the new media
*
* @param bytes The content
*
* @return a JSMedia object
*/
@JSFunction
public JSMedia newMedia(String name, byte[] bytes) {
FlattenedSolution fs = application.getFlattenedSolution();
try {
Media media = fs.getSolutionCopy().createNewMedia(new ScriptNameValidator(fs), name);
media.setPermMediaData(bytes);
media.setMimeType(MimeTypes.getContentType(bytes));
return new JSMedia(media, application.getFlattenedSolution(), true);
} catch (RepositoryException e) {
throw new RuntimeException("error createing new media with name " + name, e);
}
}
use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.
the class PersistHelper method getOrderedStyleSheets.
public static List<String> getOrderedStyleSheets(FlattenedSolution fs) {
List<String> styleSheets = new ArrayList<String>();
List<Solution> orderedModules = new ArrayList<Solution>();
orderedModules.add(fs.getSolution());
if (fs.getModules() != null) {
buildOrderedModulesList(fs.getSolution(), orderedModules, new ArrayList<Solution>(Arrays.asList(fs.getModules())));
}
for (Solution solution : orderedModules) {
if (solution.getStyleSheetID() > 0) {
Media media = fs.getMedia(solution.getStyleSheetID());
if (media != null) {
if (!styleSheets.contains(media.getName())) {
styleSheets.add(media.getName());
}
} else {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.warn("Stylesheet set for solution '" + solution.getName() + "' cannot be found");
}
}
}
return styleSheets;
}
Aggregations