use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class DisplaysAdapter method startEdit.
public static void startEdit(DataAdapterList dal, IDisplay display, IRecordInternal state) {
final IApplication application = dal.getApplication();
dal.setCurrentDisplay(display);
boolean isGlobal = false;
boolean isColumn = true;
if (display instanceof IDisplayData) {
String dataProviderID = ((IDisplayData) display).getDataProviderID();
isGlobal = dataProviderID != null && ScopesUtils.isVariableScope(dataProviderID);
if (!isGlobal && dataProviderID != null) {
// $NON-NLS-1$
String[] parts = dataProviderID.split("\\.");
IRecordInternal currState = state;
for (int i = 0; i < parts.length - 1; i++) {
IFoundSetInternal foundset = currState.getRelatedFoundSet(parts[i]);
if (foundset == null) {
break;
}
Relation r = application.getFoundSetManager().getApplication().getFlattenedSolution().getRelation(parts[i]);
currState = foundset.getRecord(foundset.getSelectedIndex());
if (currState == null) {
if (r != null && r.getAllowCreationRelatedRecords()) {
try {
currState = foundset.getRecord(foundset.newRecord(0, true));
} catch (ServoyException se) {
application.reportError(se.getLocalizedMessage(), se);
}
} else {
final ApplicationException ae = new ApplicationException(ServoyException.NO_RELATED_CREATE_ACCESS, new Object[] { parts[i] });
ae.setContext(dal.getFormController().toString());
// unfocus the current field, otherwise when the dialog is closed focus is set back to this field and the same error recurs ad infinitum.
application.looseFocus();
application.invokeLater(new Runnable() {
public void run() {
// ApplicationException knows how to translate this null into an i18n message
application.handleException(null, ae);
}
});
}
}
if (currState == null)
return;
}
isColumn = currState.getParentFoundSet().getColumnIndex(parts[parts.length - 1]) != -1 || currState.getParentFoundSet().containsCalculation(dataProviderID);
}
}
if (// globals are always allowed to set in datarenderers
isGlobal || !isColumn || state.startEditing()) {
// bit ugly should use property event here
if (application instanceof ISmartClientApplication)
((ISmartClientApplication) application).updateInsertModeIcon(display);
} else {
// loose focus first
// don't transfer focus to menu bar.. (macosx)
// application.getMainApplicationFrame().getJMenuBar().requestFocus();
application.looseFocus();
application.reportWarningInStatus(// $NON-NLS-1$
application.getI18NMessage("servoy.foundSet.error.noModifyAccess", new Object[] { state.getParentFoundSet().getDataSource() }));
}
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class PrintPreview method startPrinting.
public static void startPrinting(IApplication application, Pageable pageable, PrinterJob a_printerJob, String a_preferredPrinterName, boolean showPrinterSelectDialog, boolean avoidDialogs) {
RepaintManager currentManager = RepaintManager.currentManager(application.getPrintingRendererParent().getParent());
boolean isDoubleBufferingEnabled = false;
try {
if (currentManager != null) {
isDoubleBufferingEnabled = currentManager.isDoubleBufferingEnabled();
}
if (a_printerJob != null) {
// for plugin printing
a_printerJob.setPageable(pageable);
// $NON-NLS-1$
a_printerJob.setJobName("Servoy Print");
if (showPrinterSelectDialog) {
if (!a_printerJob.printDialog()) {
return;
}
// hide dialog
SwingHelper.dispatchEvents(100);
}
if (currentManager != null) {
currentManager.setDoubleBufferingEnabled(false);
}
a_printerJob.print();
} else {
// by default we use old system for mac, new is not always working
// $NON-NLS-1$//$NON-NLS-2$
boolean useSystemPrintDialog = Utils.getAsBoolean(application.getSettings().getProperty("useSystemPrintDialog", "" + Utils.isAppleMacOS()));
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
if (capablePrintServices == null) {
capablePrintServices = PrintServiceLookup.lookupPrintServices(flavor, pras);
}
PrintService service = null;
if (capablePrintServices == null || capablePrintServices.length == 0) {
if (avoidDialogs) {
Debug.warn("Cannot find capable print services. Print aborted.");
return;
} else {
JOptionPane.showConfirmDialog(((ISmartClientApplication) application).getMainApplicationFrame(), // $NON-NLS-1$ //$NON-NLS-2$
application.getI18NMessage("servoy.print.msg.noPrintersFound"), // $NON-NLS-1$ //$NON-NLS-2$
application.getI18NMessage("servoy.print.printing.title"), JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE);
capablePrintServices = new PrintService[0];
// must show select printer and if none found show this
showPrinterSelectDialog = true;
// we leave to system to show no printers are found, important for apple mac
useSystemPrintDialog = true;
}
} else {
// default select
service = capablePrintServices[0];
}
PrintService systemDefaultPrinter = PrintServiceLookup.lookupDefaultPrintService();
if (systemDefaultPrinter != null) {
// check if system default printer is in capable list
for (PrintService ps : capablePrintServices) {
if (ps.getName().equalsIgnoreCase(systemDefaultPrinter.getName())) {
service = systemDefaultPrinter;
break;
}
}
}
// want custom preferred printer
boolean didFindPrinter = true;
if (a_preferredPrinterName != null) {
didFindPrinter = false;
for (PrintService ps : capablePrintServices) {
if (ps.getName().equalsIgnoreCase(a_preferredPrinterName)) {
didFindPrinter = true;
service = ps;
break;
}
}
}
if (!didFindPrinter) {
if (avoidDialogs) {
Debug.warn("Cannot find capable printer for preferred form printer name '" + a_preferredPrinterName + "'. Trying to use default/any capable printer.");
} else {
// did not found the prefered , do show
showPrinterSelectDialog = true;
}
}
if (!useSystemPrintDialog) {
if (showPrinterSelectDialog) {
JFrame frame = ((ISmartClientApplication) application).getMainApplicationFrame();
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
Point loc = frame.getLocation();
service = ServiceUI.printDialog(gc, loc.x + 50, loc.y + 50, capablePrintServices, service, flavor, pras);
}
if (service != null) {
if (currentManager != null) {
currentManager.setDoubleBufferingEnabled(false);
}
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(pageable, flavor, das);
if (job != null) {
job.print(doc, pras);
} else {
// for example if the print service cancels (e.g. print to pdf and then user cancel when choosing save location)
// $NON-NLS-1$
application.reportWarning(application.getI18NMessage("servoy.print.error.cannotPrintDocument"));
}
}
} else {
a_printerJob = PrinterJob.getPrinterJob();
a_printerJob.setPageable(pageable);
// $NON-NLS-1$
a_printerJob.setJobName("Servoy Print");
if (service != null) {
a_printerJob.setPrintService(service);
}
if (showPrinterSelectDialog) {
if (!a_printerJob.printDialog()) {
return;
}
// hide dialog
SwingHelper.dispatchEvents(100);
}
if (currentManager != null) {
currentManager.setDoubleBufferingEnabled(false);
}
a_printerJob.print();
}
}
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.print.error.cannotPrintDocument"), ex);
} finally {
if (currentManager != null) {
currentManager.setDoubleBufferingEnabled(isDoubleBufferingEnabled);
}
}
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class FixedJTable method valueChanged.
/**
* @see javax.swing.JTable#valueChanged(javax.swing.event.ListSelectionEvent)
*/
@Override
public void valueChanged(ListSelectionEvent e) {
if (getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) {
if (e.getValueIsAdjusting())
return;
int rowCount = getRowCount() - 1;
int columnCount = getColumnCount() - 1;
if (rowCount < 0 || columnCount < 0) {
return;
}
int firstIndex = Math.min(rowCount, Math.max(e.getFirstIndex(), 0));
int lastIndex = Math.min(rowCount, Math.max(e.getLastIndex(), 0));
Rectangle firstRowRect1 = getCellRect(firstIndex, 0, false);
Rectangle firstRowRect2 = getCellRect(firstIndex, columnCount, false);
int paintImmediately = 0;
if (application instanceof ISmartClientApplication) {
paintImmediately = ((ISmartClientApplication) application).getPaintTableImmediately();
}
boolean valid = paintImmediately <= 0 && isValid();
if (valid) {
Rectangle currentRect = getVisibleRect();
if (currentRect.y > firstRowRect1.y) {
valid = false;
} else if ((currentRect.y + currentRect.height) <= (firstRowRect1.y + firstRowRect2.height)) {
valid = false;
}
}
scrollToSelection();
if (valid) {
super.paintImmediately(firstRowRect1.union(firstRowRect2));
} else {
repaint(firstRowRect1.union(firstRowRect2));
}
Rectangle lastRowRect1 = getCellRect(lastIndex, 0, false);
Rectangle lastRowRect2 = getCellRect(lastIndex, columnCount, false);
if (valid) {
super.paintImmediately(lastRowRect1.union(lastRowRect2));
} else {
repaint(lastRowRect1.union(lastRowRect2));
}
} else {
super.valueChanged(e);
if (!e.getValueIsAdjusting() && (selectedRowIndex != getSelectedRow())) {
scrollToSelection();
}
}
if (!e.getValueIsAdjusting()) {
selectedRowIndex = getSelectedRow();
}
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class DataCalendar method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (Boolean.TRUE.equals(application.getRuntimeProperties().get(IServiceProvider.RT_LASTFIELDVALIDATIONFAILED_FLAG)) && isValueValid()) {
if (Debug.tracing()) {
// $NON-NLS-1$
Debug.trace("Calendar not shown because a field is marked invalid");
}
return;
}
// $NON-NLS-1$
JDateChooser chooser = (JDateChooser) ((ISmartClientApplication) application).getWindow("JDateChooser");
Window windowParent = SwingUtilities.getWindowAncestor(this);
if (chooser == null || SwingUtilities.getWindowAncestor(chooser) != windowParent) {
if (chooser != null) {
chooser.dispose();
chooser = null;
// $NON-NLS-1$
((ISmartClientApplication) application).registerWindow("JDateChooser", chooser);
}
String dateFormat = TagResolver.getFormatString(Date.class, application);
if (windowParent instanceof JFrame) {
// $NON-NLS-1$
chooser = new JDateChooser((JFrame) windowParent, application.getI18NMessage("servoy.dateChooser.selectDate"), dateFormat);
} else if (windowParent instanceof JDialog) {
// $NON-NLS-1$
chooser = new JDateChooser((JDialog) windowParent, application.getI18NMessage("servoy.dateChooser.selectDate"), dateFormat);
} else {
Debug.warn("Cannot create date chooser for parent container " + windowParent);
}
// $NON-NLS-1$
if (chooser != null)
((ISmartClientApplication) application).registerWindow("JDateChooser", chooser);
}
if (chooser != null) {
enclosedComponent.requestFocus();
Object value = enclosedComponent.getValue();
if (value != null && value instanceof Date) {
Calendar cal = chooser.getSelectedDate();
cal.setTime((Date) value);
chooser.updateCalendar(cal);
} else if (value == null) {
Calendar cal = chooser.getSelectedDate();
cal.setTime(chooser.format(new Date(), enclosedComponent.getFormat()));
chooser.updateCalendar(cal);
}
if (chooser.showDialog(enclosedComponent.getFormat()) == JDateChooser.ACCEPT_OPTION) {
enclosedComponent.requestFocus();
Calendar selectedDate = chooser.getSelectedDate();
enclosedComponent.setValueExFromCalendar(selectedDate.getTime());
}
}
}
use of com.servoy.j2db.ISmartClientApplication 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);
}
}
}
}
Aggregations