use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class FormController method propagateFindMode.
/*
* _____________________________________________________________ The methods below belong to this class
*/
@Override
public void propagateFindMode(boolean findMode) {
if (!findMode) {
application.getFoundSetManager().getEditRecordList().prepareForSave(true);
}
if (isReadOnly()) {
if (view != null) {
view.setEditable(findMode);
}
}
for (IDataRenderer dataRenderer : dataRenderers) {
if (dataRenderer != null) {
// see web cell based view that is used as a tableview and portal.
if (dataRenderer instanceof IDisplay) {
((IDisplay) dataRenderer).setValidationEnabled(!findMode);
} else {
DataAdapterList dal = dataRenderer.getDataAdapterList();
// disables related data en does getText instead if getValue on fields
dal.setFindMode(findMode);
dataRenderer.setAllNonFieldsEnabled(!findMode);
}
// }
// else
// {
// //dataRenderers[i].setUIEnabled(!findMode);
// }
}
}
}
use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class DataImgMediaField method loadFromFile.
void loadFromFile() {
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(((ISmartClientApplication) application).getMainApplicationFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File f = fc.getSelectedFile();
if (editProvider != null)
editProvider.startEdit();
byte[] content = null;
if (application.isEventDispatchThread()) {
setValueObject(content = FileChooserUtils.paintingReadFile(application.getScheduledExecutor(), application, f));
} else {
setValueObject(content = FileChooserUtils.readFile(f));
}
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, f.getName());
((DataAdapterList) resolver).setValueObject(dataProviderID + IMediaFieldConstants.MIMETYPE, MimeTypes.getContentType(content, f.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);
}
}
}
}
use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class DataImgMediaField method pasteFromClipboard.
protected void pasteFromClipboard() {
try {
Transferable tr = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
byte[] data;
if (tr.isDataFlavorSupported(getByteArrayDataFlavor())) {
data = (byte[]) tr.getTransferData(getByteArrayDataFlavor());
} else {
Image img = (Image) tr.getTransferData(DataFlavor.imageFlavor);
data = SnapShot.createJPGImage(((ISmartClientApplication) application).getMainApplicationFrame(), img, -1, -1);
}
String[] fileNameAndMimeType;
if (tr.isDataFlavorSupported(getStringArrayDataFlavor())) {
fileNameAndMimeType = (String[]) tr.getTransferData(getStringArrayDataFlavor());
// use null values as this is unknown clipboard data
if (fileNameAndMimeType == null || fileNameAndMimeType.length != 2)
fileNameAndMimeType = new String[2];
} else {
// null values
fileNameAndMimeType = new String[2];
}
if (data != null && data.length != 0) {
if (editProvider != null)
editProvider.startEdit();
setValueObject(data);
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, fileNameAndMimeType[0]);
((DataAdapterList) resolver).setValueObject(dataProviderID + IMediaFieldConstants.MIMETYPE, fileNameAndMimeType[1]);
}
}
} catch (Exception e) {
Debug.error(e);
}
}
use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class DataRenderer method createDataAdapter.
void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
// IScriptExecutor can be null for a design component
FormController formController = el == null ? null : el.getFormController();
dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, formController, 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;
}
use of com.servoy.j2db.dataprocessing.DataAdapterList in project servoy-client by Servoy.
the class DataImgMediaField method saveToFile.
void saveToFile() {
if (value instanceof byte[]) {
byte[] array = (byte[]) value;
FileNameSuggestionFileChooser fc = new FileNameSuggestionFileChooser();
String fileName = null;
// dataprovider_filename and dataprovider_mimetype fields will be used like in the web TODO maybe refactor to avoid cast below
if (resolver instanceof DataAdapterList) {
Object val = ((DataAdapterList) resolver).getValueObject(((DataAdapterList) resolver).getState(), dataProviderID + IMediaFieldConstants.FILENAME);
fileName = (val instanceof String) ? (String) val : null;
}
if (fileName != null) {
fc.suggestFileName(fileName);
} else if (// jpeg
array.length > 3 && array[0] == -1 && array[1] == -40 && array[2] == -1) {
fc.suggestFileName("image.jpg");
} else if (// gif
array.length > 3 && array[0] == 0x47 && array[1] == 0x49 && array[2] == 0x46) {
fc.suggestFileName("image.gif");
} else {
fc.suggestFileName("filename.unknown");
}
int returnVal = fc.showSaveDialog(((ISmartClientApplication) application).getMainApplicationFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File f = fc.getSelectedFile();
OutputStream os = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(array);
bos.close();
} 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);
}
}
}
}
}
Aggregations