use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class DebugJ2DBClient method destroyForm.
/**
* @param formController
* @return
*/
private void destroyForm(IFormController formController) {
refreshI18NMessages(true);
if (formController.isFormVisible()) {
IFoundSetInternal foundSet = formController.getFormModel();
if (foundSet instanceof FoundSet) {
((FoundSet) foundSet).refresh();
}
String name = null;
if (formController.getForm() != null)
name = formController.getForm().getName();
if (name == null)
name = formController.getName();
if (getFormManager().getCurrentForm() == formController) {
formController.destroy();
getFormManager().showFormInCurrentContainer(name);
} else {
SwingForm swingForm = (SwingForm) formController.getFormUI();
Container container = swingForm.getParent();
boolean isNavigator = false;
boolean isWindow = false;
boolean isLookupPanel = false;
if (container instanceof MainPanel) {
isNavigator = ((MainPanel) container).getNavigator() == formController;
} else if (container instanceof FormLookupPanel) {
isLookupPanel = true;
} else {
while (container != null && !(container instanceof FormWindow)) {
container = container.getParent();
}
if (container instanceof FormWindow) {
isWindow = true;
}
}
formController.destroy();
if (isLookupPanel) {
FormLookupPanel flp = (FormLookupPanel) container;
FormController newFormController = flp.getFormPanel();
if (newFormController != null) {
// deleted in developer ?
newFormController.loadData(foundSet, null);
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
newFormController.notifyVisible(true, invokeLaterRunnables);
Utils.invokeLater(this, invokeLaterRunnables);
}
} else if (isNavigator) {
// TODO isNavigator check will always be false for NGClient?
FormController navigator = ((FormManager) getFormManager()).getFormController(name, container);
if (navigator != null) {
navigator.loadData(foundSet, null);
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
navigator.notifyVisible(true, invokeLaterRunnables);
Utils.invokeLater(this, invokeLaterRunnables);
}
mainPanel.setNavigator(navigator);
} else if (isWindow) {
// TODO isWindow check will always be false for NGClient?
FormWindow w = (FormWindow) container;
((FormManager) getFormManager()).showFormInMainPanel(name, w.getMainContainer(), w.getTitle(), false, w.getName());
}
}
} else {
formController.destroy();
}
return;
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class SessionClient method getContext.
private Pair<IRecordInternal, FormScope> getContext(String contextName) {
try {
String visibleFormName = contextName;
String dataContext = null;
if (contextName != null) {
// $NON-NLS-1$
StringTokenizer tk = new StringTokenizer(contextName, ".");
String token = tk.nextToken();
if (// $NON-NLS-1$
token.equals("forms") && tk.hasMoreTokens()) {
visibleFormName = tk.nextToken();
if (tk.hasMoreTokens())
token = tk.nextToken();
}
if (// $NON-NLS-1$
!token.equals("foundset")) {
// todo why is this always also assigned to the datacontext?
// shouldnt the above if be: if (token.equals("foundset") && st.hasMoreTokes()) dataContext == st.nextToken();
// because now this data context will just be set to a form name if the contextName is just a form. (which in many cases it is defined like that)
dataContext = token;
}
}
if (visibleFormName == null) {
IForm tmp = ((FormManager) getFormManager()).getCurrentForm();
if (tmp != null)
visibleFormName = tmp.getName();
}
if (visibleFormName != null) {
// just overwrite the above assignment again if the datacontext is really also the form, so it wont be used later on.
if (Utils.stringSafeEquals(visibleFormName, dataContext)) {
dataContext = null;
}
FormController fp = ((FormManager) getFormManager()).leaseFormPanel(visibleFormName);
if (!fp.isShowingData()) {
if (fp.wantEmptyFoundSet()) {
if (fp.getFormModel() != null)
fp.getFormModel().clear();
} else {
fp.loadAllRecords();
}
}
IFoundSetInternal fs = fp.getFoundSet();
if (fs != null) {
int idx = fs.getSelectedIndex();
if (idx < 0)
idx = 0;
IRecordInternal r = fs.getRecord(idx);
if (r != null) {
if (dataContext != null) {
IFoundSetInternal rfs = r.getRelatedFoundSet(dataContext);
// rfs can be null because dataContext can just be a anything see above
if (rfs != null) {
r = rfs.getRecord(rfs.getSelectedIndex());
}
}
return new Pair<IRecordInternal, FormScope>(r, fp.getFormScope());
}
}
return new Pair<IRecordInternal, FormScope>(null, fp.getFormScope());
}
} catch (Exception e) {
Debug.error(e);
}
return null;
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class WebAccordionPanel method registerSelectionListeners.
private void registerSelectionListeners(IRecordInternal parentState, String relationName) {
// $NON-NLS-1$
String[] parts = relationName.split("\\.");
IRecordInternal currentRecord = parentState;
for (int i = 0; currentRecord != null && i < parts.length - 1; i++) {
IFoundSetInternal fs = currentRecord.getRelatedFoundSet(parts[i]);
if (fs instanceof ISwingFoundSet) {
related.add((ISwingFoundSet) fs);
((ISwingFoundSet) fs).getSelectionModel().addListSelectionListener(this);
}
currentRecord = (fs == null) ? null : fs.getRecord(fs.getSelectedIndex());
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class WebAccordionPanel method showFoundSet.
protected void showFoundSet(WebTabFormLookup flp, IRecordInternal parentState, List<SortColumn> sort) {
deregisterSelectionListeners();
if (!flp.isReady())
return;
FormController fp = flp.getWebForm().getController();
if (fp != null && flp.getRelationName() != null) {
IFoundSetInternal relatedFoundset = parentState == null ? null : parentState.getRelatedFoundSet(flp.getRelationName(), sort);
registerSelectionListeners(parentState, flp.getRelationName());
fp.loadData(relatedFoundset, null);
}
ITagResolver resolver = getTagResolver(parentState);
// refresh tab text
for (int i = 0; i < allTabs.size(); i++) {
WebTabHolder element = allTabs.get(i);
if (element.getPanel() == flp) {
element.refreshTagStrings(resolver);
break;
}
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class WebForm method print.
// public void print(boolean showDialogs, boolean printCurrentRecordOnly, boolean showPrinterSelectDialog, int zoomFactor, PrinterJob printerJob)
// {
// print(showDialogs, printCurrentRecordOnly, showPrinterSelectDialog, printerJob);
// }
/**
* @see com.servoy.j2db.IFormUIInternal#print(boolean, boolean, boolean, java.awt.print.PrinterJob)
*/
public void print(boolean showDialogs, boolean printCurrentRecordOnly, boolean showPrinterSelectDialog, PrinterJob printerJob) {
IFoundSetInternal fs = formController.getFoundSet();
try {
if (printCurrentRecordOnly) {
fs = fs.copyCurrentRecordFoundSet();
}
} catch (ServoyException e1) {
Debug.error(e1);
}
IApplication application = formController.getApplication();
ByteArrayOutputStream baos = null;
MainPage page = null;
if (printerJob == null) {
page = (MainPage) findPage();
if (page == null) {
IMainContainer tmp = ((FormManager) application.getFormManager()).getCurrentContainer();
if (tmp instanceof MainPage)
page = (MainPage) tmp;
}
// if "page" is still null then there is no wicket front-end for this client - so printing is not intended to reach the client; print on the server instead
// (can happen for batch processors for example)
}
if (page != null) {
baos = new ByteArrayOutputStream();
StreamPrintServiceFactory[] factories = null;
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(((PluginManager) application.getPluginManager()).getClassLoader());
// $NON-NLS-1$
factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, "application/pdf");
if (factories == null || factories.length == 0) {
// $NON-NLS-1$
Debug.error("No suitable pdf printer found");
return;
}
} finally {
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
try {
FormPreviewPanel fpp = new FormPreviewPanel(application, formController, fs);
// AWT stuff happens here, so execute it in the AWT Event Thread - else exceptions can occur
// for example in JEditorPane while getting the preferred size & stuff
processFppInAWTEventQueue(fpp, application);
StreamPrintService sps = factories[0].getPrintService(baos);
Doc doc = new SimpleDoc(fpp.getPageable(), flavor, null);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
sps.createPrintJob().print(doc, pras);
fpp.destroy();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.printDocument"), ex);
}
// $NON-NLS-1$
String contentType = "application/pdf";
// BTW, "application/octet-stream" works for all browsers, but it is not that accurate
if (// if it's not batch processor/jsp, because if it is, then getClientInfo() gives NullPointerException
application.getApplicationType() != IApplication.HEADLESS_CLIENT) {
ClientInfo info = Session.get().getClientInfo();
if (info instanceof WebClientInfo) {
String userAgent = ((WebClientInfo) info).getProperties().getNavigatorUserAgent();
if (// $NON-NLS-1$
userAgent != null && userAgent.toLowerCase().contains("safari")) {
// $NON-NLS-1$
contentType = "application/octet-stream";
}
}
}
// $NON-NLS-1$ //$NON-NLS-2$
String url = page.serveResource(formController.getName() + ".pdf", baos.toByteArray(), contentType, "attachment");
// $NON-NLS-1$
page.setShowURLCMD(url, "_self", null, 0, false);
} else {
try {
FormPreviewPanel fpp = new FormPreviewPanel(application, formController, fs);
// AWT stuff happens here, so execute it in the AWT Event Thread - else exceptions can occur
// for example in JEditorPane while getting the preferred size & stuff
processFppInAWTEventQueue(fpp, application);
PrintPreview.startPrinting(application, fpp.getPageable(), printerJob, formController.getPreferredPrinterName(), false, true);
fpp.destroy();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.printDocument"), ex);
}
}
}
Aggregations