use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class DataImgMediaField method copyToClipboard.
protected void copyToClipboard() {
try {
// we copy to clipboard as byte array and filename/mimetype array used when pasting into another media field and as image icon for external pastes or if byte array is not available (and for external types)
final Icon icon = enclosedComponent.getIcon();
final byte[] bytes = getByteArrayContents(value);
final String[] fileNameAndMime = new String[2];
if (resolver instanceof DataAdapterList) {
DataAdapterList dal = ((DataAdapterList) resolver);
Object tmp = dal.getValueObject(dal.getState(), dataProviderID + IMediaFieldConstants.FILENAME);
fileNameAndMime[0] = (tmp instanceof String) ? (String) tmp : null;
tmp = dal.getValueObject(dal.getState(), dataProviderID + IMediaFieldConstants.MIMETYPE);
fileNameAndMime[1] = (tmp instanceof String) ? (String) tmp : null;
}
if (icon instanceof ImageIcon || icon instanceof MyImageIcon) {
Transferable tr = new Transferable() {
public DataFlavor[] getTransferDataFlavors() {
List<DataFlavor> list = new ArrayList<DataFlavor>(3);
if (bytes != null)
list.add(getByteArrayDataFlavor());
list.add(DataFlavor.imageFlavor);
if (fileNameAndMime[0] != null || fileNameAndMime[1] != null) {
list.add(getStringArrayDataFlavor());
list.add(DataFlavor.stringFlavor);
}
return list.toArray(new DataFlavor[list.size()]);
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return DataFlavor.imageFlavor.equals(flavor) || (bytes != null && getByteArrayDataFlavor().equals(flavor)) || ((fileNameAndMime[0] != null || fileNameAndMime[1] != null) && (getStringArrayDataFlavor().equals(flavor) || DataFlavor.stringFlavor.equals(flavor)));
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
if (DataFlavor.imageFlavor.equals(flavor)) {
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
} else if (icon instanceof MyImageIcon) {
return ((MyImageIcon) icon).getOriginal().getImage();
}
} else if (getByteArrayDataFlavor().equals(flavor)) {
return bytes;
} else if (getStringArrayDataFlavor().equals(flavor)) {
return fileNameAndMime;
} else if (DataFlavor.stringFlavor.equals(flavor)) {
return (fileNameAndMime[0] != null ? "Filename: '" + fileNameAndMime[0] + "' " : "") + (fileNameAndMime[1] != null ? "Type: '" + fileNameAndMime[1] + "'" : "");
}
return null;
}
};
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(tr, null);
}
} catch (Exception e) {
Debug.error(e);
}
}
use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class DataImgMediaField method drop.
public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
Transferable tr = dropTargetDropEvent.getTransferable();
if (popup != null && tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
if (iterator.hasNext()) {
try {
File file = (File) iterator.next();
if (editProvider != null)
editProvider.startEdit();
byte[] content = FileChooserUtils.paintingReadFile(application.getScheduledExecutor(), application, file);
setValueObject(content);
if (editProvider != null)
editProvider.commitData();
// dataprovider_filename and dataprovider_mimetype fields will be set like in the web TODO maybe refactor to avoid cast below and existence of method setValueObject in DataAdapterList
if (resolver instanceof DataAdapterList) {
((DataAdapterList) resolver).setValueObject(dataProviderID + IMediaFieldConstants.FILENAME, file.getName());
((DataAdapterList) resolver).setValueObject(dataProviderID + IMediaFieldConstants.MIMETYPE, MimeTypes.getContentType(content, file.getName()));
}
} catch (Exception e) {
if (application instanceof ISmartClientApplication) {
((ISmartClientApplication) application).reportError(this, application.getI18NMessage("servoy.imageMedia.error.loading"), e);
} else {
application.reportError(application.getI18NMessage("servoy.imageMedia.error.loading"), e);
}
}
}
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
} else {
Debug.trace("Rejected");
dropTargetDropEvent.rejectDrop();
}
} catch (Exception io) {
Debug.error(io);
dropTargetDropEvent.rejectDrop();
}
}
use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class WebDataRenderer method createDataAdapter.
void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, el.getFormController(), null, undoManager);
// make it really fields only
HashMap<IPersist, IDisplay> f = new HashMap<IPersist, IDisplay>();
Iterator<Map.Entry<IPersist, IDisplay>> it = fieldComponents.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<IPersist, IDisplay> element = it.next();
if (element.getValue() instanceof IDisplayData) {
// String id = ((IDisplayData)element.getValue()).getDataProviderID();
// if (dataProviderLookup.getDataProvider(id) instanceof ScriptVariable)
// {
// globalFields.add(element.getValue());
// }
f.put(element.getKey(), element.getValue());
}
}
fieldComponents = f;
}
Aggregations