use of com.servoy.j2db.ISmartClientApplication 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.ISmartClientApplication in project servoy-client by Servoy.
the class SwingForm method printPreview.
/**
* @see com.servoy.j2db.IFormUIInternal#printPreview(boolean, boolean, java.awt.print.PrinterJob)
*/
public void printPreview(boolean showDialogs, boolean printCurrentRecordOnly, int zoomFactor, PrinterJob printerJob) {
ISmartClientApplication application = (ISmartClientApplication) formController.getApplication();
try {
// TODO do a print preview even if records are not saved?
if (application.getFoundSetManager().getEditRecordList().stopEditing(false) != ISaveConstants.STOPPED)
return;
IFoundSetInternal set = formController.getFormModel();
if (set == null) {
if (showDialogs) {
// $NON-NLS-1$
JOptionPane.showMessageDialog(// $NON-NLS-1$
application.getMainApplicationFrame(), // $NON-NLS-1$
Messages.getString("servoy.formPanel.error.noRecordsToPrint"), Messages.getString("servoy.general.warning"), // $NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
}
return;
}
if (showDialogs) {
if (// test if foundset is zero. if so ask if really want to print/preview
set.getSize() == 0) {
int val = JOptionPane.showConfirmDialog(application.getMainApplicationFrame(), // $NON-NLS-1$//$NON-NLS-2$
Messages.getString("servoy.formPanel.error.noRecordsToPrint"), // $NON-NLS-1$//$NON-NLS-2$
Messages.getString("servoy.general.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (val != JOptionPane.OK_OPTION) {
return;
}
} else if (!printCurrentRecordOnly) {
int option = willingToPrint(set);
if (option == 2) {
printCurrentRecordOnly = true;
} else if (option == 1) {
// cancel
return;
}
}
}
if (printCurrentRecordOnly) {
set = set.copyCurrentRecordFoundSet();
}
((FormManager) application.getFormManager()).showPreview(formController, set, zoomFactor, printerJob);
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(Messages.getString("servoy.formPanel.error.printPreview"), ex);
}
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class SwingForm method showYesNoQuestionDialog.
public boolean showYesNoQuestionDialog(IApplication application, String message, String title) {
// create custom Yes/No buttons to avoid bug 129045 (ENTER from this dialog closing and showing the dialog again
// because the dialog closes on ENTER press and it is reopened on ENTER release) - reproducible with Servoy Developer 3.5.7_05-build 520 / Java version 1.5.0_11-b03 (Windows XP)
Component parentComponent = ((ISmartClientApplication) application).getMainApplicationFrame();
Locale l = parentComponent.getLocale();
// $NON-NLS-1$ //$NON-NLS-2$
JButton buttonYes = getNoDoClickJButton(UIManager.getString("OptionPane.yesButtonText", l), getMnemonic("OptionPane.yesButtonMnemonic", l));
// $NON-NLS-1$ //$NON-NLS-2$
JButton buttonNo = getNoDoClickJButton(UIManager.getString("OptionPane.noButtonText", l), getMnemonic("OptionPane.noButtonMnemonic", l));
final JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, new Object[] { buttonYes, buttonNo }, buttonYes);
// $NON-NLS-1$
Font buttonFont = (Font) UIManager.get("OptionPane.buttonFont", parentComponent.getLocale());
if (buttonFont != null) {
buttonYes.setFont(buttonFont);
buttonNo.setFont(buttonFont);
}
// $NON-NLS-1$
int threshhold = UIManager.getInt("OptionPane.buttonClickThreshhold", parentComponent.getLocale());
buttonYes.setMultiClickThreshhold(threshhold);
buttonNo.setMultiClickThreshhold(threshhold);
ActionListener selectButtonActionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
pane.setValue(e.getSource());
}
};
buttonYes.addActionListener(selectButtonActionListener);
buttonNo.addActionListener(selectButtonActionListener);
pane.setInitialValue(buttonYes);
pane.setComponentOrientation(((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent).getComponentOrientation());
JDialog dialog = pane.createDialog(parentComponent, title);
pane.selectInitialValue();
dialog.setVisible(true);
dialog.dispose();
return pane.getValue() == buttonYes;
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class SwingForm method showSortDialog.
public void showSortDialog(IApplication app, String options) {
ISmartClientApplication application = (ISmartClientApplication) app;
try {
Table t = (Table) formController.getTable();
if (t != null) {
List<SortColumn> sortColumns = null;
if ((options == null || options.length() == 0) && formController.getFormModel() instanceof FoundSet) {
sortColumns = ((FoundSet) formController.getFormModel()).getLastSortColumns();
} else {
sortColumns = ((FoundSetManager) application.getFoundSetManager()).getSortColumns(t, options);
}
Window window = SwingUtilities.getWindowAncestor(this);
if (window == null)
window = application.getMainApplicationFrame();
// $NON-NLS-1$
SortDialog nfd = (SortDialog) application.getWindow("SortDialog");
if (nfd == null || nfd.getOwner() != window) {
if (window instanceof Frame) {
nfd = new SortDialog((Frame) window, application);
} else if (window instanceof Dialog) {
nfd = new SortDialog((Dialog) window, application);
}
// $NON-NLS-1$
application.registerWindow("SortDialog", nfd);
}
List<SortColumn> list = nfd.showDialog(t, sortColumns);
if (list != null)
formController.sort(list, false);
}
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(Messages.getString("servoy.formPanel.error.sortRecordsDialog"), ex);
}
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class ScriptEngine method executeFunction.
public Object executeFunction(Function f, Scriptable scope, Scriptable thisObject, Object[] args, boolean focusEvent, boolean throwException) throws Exception {
if (!application.isSolutionLoaded()) {
return null;
}
// find function
Object retValue = null;
if (f != null) {
String userUidBefore = null;
if (Context.getCurrentContext() == null) {
userUidBefore = application.getClientInfo().getUserUid();
}
Context cx = Context.enter();
// String clientID = application.getClientID();
try {
if (application instanceof ISmartClientApplication) {
((ISmartClientApplication) application).setPaintTableImmediately(false);
}
// wrap objects when needed (to support typeof(arguments[0]) )
Object[] wrappedArgs;
if (args == null) {
wrappedArgs = new Object[0];
} else {
wrappedArgs = new Object[args.length];
for (int i = 0; i < args.length; i++) {
if (args[i] != null) {
wrappedArgs[i] = cx.getWrapFactory().wrap(cx, scope, args[i], args[i].getClass());
}
}
}
// String solutionName = application.getSolutionName();
// IPerformanceRegistry performanceRegistry = (application.getApplicationServerAccess() != null &&
// !(application instanceof ISmartClientApplication)
// ? application.getApplicationServerAccess().getFunctionPerfomanceRegistry() : null);
// performanceData = performanceRegistry != null ? performanceRegistry.getPerformanceData(solutionName) : null;
// //run
// if (performanceData != null)
// {
// String methodName = null;
// methodName = f.getClassName();
// if (f instanceof NativeFunction) methodName = ((NativeFunction)f).getFunctionName();
// String scopeName = scope.getClassName();
// if (scope instanceof LazyCompilationScope) scopeName = ((LazyCompilationScope)scope).getScopeName();
// if (scope instanceof FoundSet)
// {
// Scriptable parentScope = ((FoundSet)scope).getPrototype();
// if (parentScope instanceof LazyCompilationScope)
// {
// scopeName = ((LazyCompilationScope)parentScope).getScopeName();
// }
// }
//
// methodName = scopeName + "." + methodName; //$NON-NLS-1$
// // application.addPerformanceTiming(server, sql, 0 - t1);
// pfUuid = performanceData.startAction(methodName, System.currentTimeMillis(), IDataServer.METHOD_CALL, clientID);
// }
retValue = f.call(cx, scope, thisObject, wrappedArgs);
if (retValue instanceof Wrapper) {
retValue = ((Wrapper) retValue).unwrap();
}
} catch (Exception ex) {
if (scope instanceof TableScope || throwException) {
// is calc report back via other way
throw ex;
} else if (application.getSolution() != null) {
Throwable t = ex;
while (t.getCause() != null) {
t = t.getCause();
}
String msg = t.getLocalizedMessage();
if (scope instanceof FormScope) {
msg += " (Form Context: " + ((FormScope) scope).getScopeName() + ')';
} else if (scope instanceof GlobalScope) {
msg += " (Global Scope Context: " + ((GlobalScope) scope).getScopeName() + ')';
} else if (scope instanceof LazyCompilationScope) {
msg += " (Scope Context: " + ((LazyCompilationScope) scope).getScopeName() + ')';
}
if (args != null) {
for (Object arg : args) {
if (arg instanceof JSEvent) {
msg += ", " + arg;
break;
}
}
}
application.handleException(msg, ex);
} else {
// $NON-NLS-1$
Debug.trace("Solution already closed, ignoring exception", ex);
}
} finally {
if (application instanceof ISmartClientApplication) {
((ISmartClientApplication) application).setPaintTableImmediately(true);
}
// else if (pfUuid != null)
// {
// performanceData.endAction(pfUuid, clientID);
// }
Context.exit();
}
testClientUidChange(scope, userUidBefore);
}
return retValue;
}
Aggregations