Search in sources :

Example 11 with ISmartClientApplication

use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.

the class SwingForm method willingToPrint.

/**
 * @return 0 when ok,1 when cancel,2 when current rec.
 */
private int willingToPrint(IFoundSetInternal formModel) {
    // test if foundset is big. if so ask if really want to print/preview
    if (formModel.getSize() >= ((FoundSetManager) formModel.getFoundSetManager()).config.pkChunkSize()) {
        Object[] options = new String[] { // $NON-NLS-1$
        Messages.getString("servoy.button.ok"), // $NON-NLS-1$
        Messages.getString("servoy.button.cancel"), // $NON-NLS-1$
        Messages.getString("servoy.formPanel.printCurrentRecord") };
        ISmartClientApplication application = (ISmartClientApplication) formController.getApplication();
        return JOptionPane.showOptionDialog(application.getMainApplicationFrame(), // $NON-NLS-1$
        Messages.getString("servoy.formPanel.message.largeResultset", new Object[] { new Integer(formModel.getSize()) }), // $NON-NLS-1$
        Messages.getString("servoy.general.warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2]);
    }
    return 0;
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject)

Example 12 with ISmartClientApplication

use of com.servoy.j2db.ISmartClientApplication 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)

Example 13 with ISmartClientApplication

use of com.servoy.j2db.ISmartClientApplication 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();
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) Transferable(java.awt.datatransfer.Transferable) Iterator(java.util.Iterator) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) List(java.util.List) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) ArrayList(java.util.ArrayList) File(java.io.File) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Aggregations

ISmartClientApplication (com.servoy.j2db.ISmartClientApplication)13 Point (java.awt.Point)6 DataAdapterList (com.servoy.j2db.dataprocessing.DataAdapterList)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)4 IOException (java.io.IOException)4 File (java.io.File)3 JDialog (javax.swing.JDialog)3 JFrame (javax.swing.JFrame)3 ApplicationException (com.servoy.j2db.ApplicationException)2 ServoyException (com.servoy.j2db.util.ServoyException)2 Window (java.awt.Window)2 Transferable (java.awt.datatransfer.Transferable)2 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)2 ExitScriptException (com.servoy.j2db.ExitScriptException)1 FormManager (com.servoy.j2db.FormManager)1 IApplication (com.servoy.j2db.IApplication)1 DataException (com.servoy.j2db.dataprocessing.DataException)1 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1