Search in sources :

Example 1 with DataAdapterList

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);
        // }
        }
    }
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) IDisplay(com.servoy.j2db.dataprocessing.IDisplay)

Example 2 with DataAdapterList

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);
            }
        }
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) JFileChooser(javax.swing.JFileChooser) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) File(java.io.File) Point(java.awt.Point) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Example 3 with DataAdapterList

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);
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) Transferable(java.awt.datatransfer.Transferable) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) Image(java.awt.Image) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Example 4 with DataAdapterList

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;
}
Also used : FormController(com.servoy.j2db.FormController) HashMap(java.util.HashMap) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) IPersist(com.servoy.j2db.persistence.IPersist) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with DataAdapterList

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);
                }
            }
        }
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) FileNameSuggestionFileChooser(com.servoy.j2db.util.gui.FileNameSuggestionFileChooser) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Point(java.awt.Point) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Aggregations

DataAdapterList (com.servoy.j2db.dataprocessing.DataAdapterList)8 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)5 IOException (java.io.IOException)5 ISmartClientApplication (com.servoy.j2db.ISmartClientApplication)4 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)3 Transferable (java.awt.datatransfer.Transferable)3 File (java.io.File)3 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IPersist (com.servoy.j2db.persistence.IPersist)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FormController (com.servoy.j2db.FormController)1 ScriptVariable (com.servoy.j2db.persistence.ScriptVariable)1 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)1 FileNameSuggestionFileChooser (com.servoy.j2db.util.gui.FileNameSuggestionFileChooser)1 MyImageIcon (com.servoy.j2db.util.gui.MyImageIcon)1 Image (java.awt.Image)1 DataFlavor (java.awt.datatransfer.DataFlavor)1