use of com.servoy.j2db.dataprocessing.FoundSet 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.FoundSet 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.dataprocessing.FoundSet in project servoy-client by Servoy.
the class WebEventExecutor method setSelectedIndex.
/**
* @param component
*/
@SuppressWarnings("nls")
public static boolean setSelectedIndex(Component component, AjaxRequestTarget target, int modifiers, boolean bHandleMultiselect) {
WebForm parentForm = component.findParent(WebForm.class);
WebCellBasedView tableView = null;
if (parentForm != null) {
int parentFormViewType = parentForm.getController().getForm().getView();
if (parentFormViewType == FormController.TABLE_VIEW || parentFormViewType == FormController.LOCKED_TABLE_VIEW || parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
tableView = component.findParent(WebCellBasedView.class);
if (tableView == null) {
// the component is not part of the table view (it is on other form part), so ignore selection change
return true;
} else
tableView.setSelectionMadeByCellAction();
if (parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
if (component instanceof WebCellBasedViewListViewItem) {
((WebCellBasedViewListViewItem) component).markSelected(target);
} else {
WebCellBasedViewListViewItem listViewItem = component.findParent(WebCellBasedView.WebCellBasedViewListViewItem.class);
if (listViewItem != null) {
listViewItem.markSelected(target);
}
}
}
}
}
// search for recordItem model
Component recordItemModelComponent = component;
IModel<?> someModel = recordItemModelComponent.getDefaultModel();
while (!(someModel instanceof RecordItemModel)) {
recordItemModelComponent = recordItemModelComponent.getParent();
if (recordItemModelComponent == null)
break;
someModel = recordItemModelComponent.getDefaultModel();
}
if (someModel instanceof RecordItemModel) {
if (!(component instanceof WebCellBasedViewListViewItem)) {
// update the last rendered value for the events component (if updated)
((RecordItemModel) someModel).updateRenderedValue(component);
}
IRecordInternal rec = (IRecordInternal) someModel.getObject();
if (rec != null) {
int index;
IFoundSetInternal fs = rec.getParentFoundSet();
if (someModel instanceof FoundsetRecordItemModel) {
index = ((FoundsetRecordItemModel) someModel).getRowIndex();
} else {
// this is used only on "else", because a "plugins.rawSQL.flushAllClientsCache" could result in index = -1 although the record has not changed (but record & underlying row instances changed)
index = fs.getRecordIndex(rec);
}
if (fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect()) {
// set the selected record
ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties();
String navPlatform = clp.getNavigatorPlatform();
int controlMask = (navPlatform != null && navPlatform.toLowerCase().indexOf("mac") != -1) ? Event.META_MASK : Event.CTRL_MASK;
boolean toggle = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & controlMask) != 0);
boolean extend = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.SHIFT_MASK) != 0);
boolean isRightClick = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.ALT_MASK) != 0);
if (!isRightClick) {
if (!toggle && !extend && tableView != null && tableView.getDragNDropController() != null && Arrays.binarySearch(((FoundSet) fs).getSelectedIndexes(), index) > -1) {
return true;
}
if (toggle || extend) {
if (bHandleMultiselect) {
if (toggle) {
int[] selectedIndexes = ((FoundSet) fs).getSelectedIndexes();
ArrayList<Integer> selectedIndexesA = new ArrayList<Integer>();
Integer selectedIndex = new Integer(index);
for (int selected : selectedIndexes) selectedIndexesA.add(new Integer(selected));
if (selectedIndexesA.indexOf(selectedIndex) != -1) {
if (selectedIndexesA.size() > 1) {
((ISwingFoundSet) fs).getSelectionModel().removeSelectionInterval(selectedIndex, selectedIndex);
}
} else {
((ISwingFoundSet) fs).getSelectionModel().addSelectionInterval(selectedIndex, selectedIndex);
}
} else if (extend) {
int anchor = ((FoundSet) fs).getSelectedIndex();
int min = Math.min(anchor, index);
int max = Math.max(anchor, index);
((ISwingFoundSet) fs).getSelectionModel().setSelectionInterval(min, max);
}
}
} else if (index != -1 || fs.getSize() == 0) {
fs.setSelectedIndex(index);
}
}
} else if (!isIndexSelected(fs, index))
fs.setSelectedIndex(index);
if (!isIndexSelected(fs, index) && !(fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect())) {
// setSelectedIndex failed, probably due to validation failed, do a blur()
if (target != null)
target.appendJavascript("var toBlur = document.getElementById(\"" + component.getMarkupId() + "\");if (toBlur) toBlur.blur();");
return false;
}
}
}
return true;
}
use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class FormPreviewPanel method process.
// build the chain and fill the renderers,returns number of pages
public int process() throws Exception {
// clear
root = null;
// set size of this panel
orgWidth = new Dimension((int) (currentPageFormat.getWidth() * (1 / factor)), (int) (currentPageFormat.getHeight() * (1 / factor)));
applySize();
part_panels = createPartPanels();
Form form = controllerBeingPreviewed.getForm();
// otherwise you cannot print multiple columns (int) (application.getPageFormat().getImageableWidth()*(1/factor));
int w = form.getWidth();
try {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
Map componentsUsingSliding = application.getDataRenderFactory().completeRenderers(application, form, controllerBeingPreviewed.getScriptExecuter(), part_panels, w, true, null, null);
PropertyCopy.copyExistingPrintableProperties(application, controllerBeingPreviewed, part_panels);
Iterator<DataRenderer> panels = part_panels.values().iterator();
while (panels.hasNext()) {
DataRenderer panel = panels.next();
panel.setComponentsUsingSliding(componentsUsingSliding);
DataRendererFactory.addSpringsBetweenComponents(application, panel);
}
// $NON-NLS-1$
Debug.trace("usesSliding " + (componentsUsingSliding.size() != 0));
} finally {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", null);
}
// create list
renderParent = application.getPrintingRendererParent();
plist = new PageList(application, this, renderParent);
PartNode node = null;
// create the chain based on the sort,LAST node must be the body part (is virtal added if not present)
Part body = null;
FormController fp = ((FormManager) application.getFormManager()).leaseFormPanel(controllerBeingPreviewed.getName());
if (fp != null && !fp.isShowingData()) {
// List lst = fp.getFormModel().getLastSearchColumns();
if (fp.wantEmptyFoundSet()) {
if (fp.getFormModel() != null)
fp.getFormModel().clear();
} else {
fp.loadAllRecords();
}
// fp.getFormModel().sort(lst);
}
List<SortColumn> sortColumns = ((FoundSet) formData).getLastSortColumns();
if (formData.getSize() != 0) {
if (sortColumns != null) {
Set<String> consumed = new HashSet<String>();
for (int i = 0; i < sortColumns.size(); i++) {
SortColumn sc = sortColumns.get(i);
Iterator<Part> it = part_panels.keySet().iterator();
while (it.hasNext()) {
Part part = it.next();
DataRenderer dr = part_panels.get(part);
if (part.getPartType() == Part.BODY) {
body = part;
continue;
}
if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
IRecordInternal state = new PageNumberState(formData, plist);
plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
continue;
}
boolean match = false;
int inlineCount = 0;
List<SortColumn> partSortColumns = new ArrayList<SortColumn>();
SortColumn lastMatch = sc;
String groupByDataproviders = part.getGroupbyDataProviderIDs() != null ? part.getGroupbyDataProviderIDs() : "";
// $NON-NLS-1$ //$NON-NLS-2$
StringTokenizer tk = new StringTokenizer("" + groupByDataproviders.toLowerCase(), ", ");
int tokenCount = tk.countTokens();
String[] ids = new String[tokenCount];
for (; inlineCount < tokenCount; inlineCount++) {
String id = tk.nextToken();
ids[inlineCount] = id;
if (lastMatch.getDataProviderID().equals(id)) {
partSortColumns.add(lastMatch);
if ((i + inlineCount + 1) < sortColumns.size()) {
lastMatch = sortColumns.get(i + inlineCount + 1);
if (part.getPartType() == Part.LEADING_SUBSUMMARY && consumed.contains(lastMatch)) {
break;
}
} else {
break;
}
} else {
break;
}
}
if (// did all match?
tokenCount > 0 && partSortColumns.size() == tokenCount) {
match = true;
if (part.getPartType() == Part.LEADING_SUBSUMMARY) {
for (String element : ids) {
consumed.add(element);
}
}
}
if (match) {
SortColumn[] array = new SortColumn[partSortColumns.size()];
partSortColumns.toArray(array);
if (// create root
root == null) {
root = new PartNode(this, part, dr, renderParent, array);
node = root;
} else {
if (!tryToPlaceInExistingNodes(part, dr, array)) {
PartNode newNode = new PartNode(this, part, dr, renderParent, array);
node.setChild(newNode);
node = newNode;
}
}
}
}
}
PartNode newNode = null;
if (body == null) {
// a virtual body (when no body is placed in the parts)
newNode = new PartNode(this, null, null, renderParent, null);
} else {
// the body
newNode = new PartNode(this, body, part_panels.get(body), renderParent, null);
}
if (node != null) {
node.setChild(newNode);
} else {
root = newNode;
}
} else // no sort...
{
if (// search for body
body == null) {
Iterator<Part> it = part_panels.keySet().iterator();
while (it.hasNext()) {
Part part = it.next();
DataRenderer dr = part_panels.get(part);
IRecordInternal state = new PageNumberState(formData, plist);
if (part.getPartType() == Part.BODY) {
body = part;
continue;
}
if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
continue;
}
}
}
if (body == null) {
// a virtual body (when no body is placed in the parts)
root = new PartNode(this, null, null, renderParent, null);
} else // if (body != null)
{
// the body
root = new PartNode(this, body, part_panels.get(body), renderParent, null);
}
}
}
try {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
long t1 = System.currentTimeMillis();
// fill the renderers with data
if (root != null) {
// dump chain
// $NON-NLS-1$
Debug.trace("Root " + root);
QuerySelect sqlString = ((FoundSet) formData).getQuerySelectForReading();
Table table = formData.getSQLSheet().getTable();
FoundSet fs = (FoundSet) ((FoundSetManager) application.getFoundSetManager()).getNewFoundSet(table, null, sortColumns);
fs.browseAll(sqlString);
long t3 = System.currentTimeMillis();
List<DataRendererDefinition> childRetval = root.process(this, fs, table, sqlString);
long t4 = System.currentTimeMillis();
if (Debug.tracing()) {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.trace("Database queries took " + ((t4 - t3) / 1000f) + " second");
}
if (childRetval != null) {
for (int i = 0; i < childRetval.size(); i++) {
plist.addPanel(childRetval.get(i));
}
}
}
plist.finish();
long t2 = System.currentTimeMillis();
int pageCount = plist.getNumberOfPages();
// dump
if (Debug.tracing()) {
Debug.trace(plist);
// $NON-NLS-1$ //$NON-NLS-2$
Debug.trace("Generated " + pageCount / ((t2 - t1) / 1000f) + " printable pages per second");
}
} finally {
// $NON-NLS-1$
application.getRuntimeProperties().put("isPrinting", null);
}
renderParent.removeAll();
return plist.getNumberOfPages();
}
use of com.servoy.j2db.dataprocessing.FoundSet in project servoy-client by Servoy.
the class BasicFormController method setModel.
protected boolean setModel(IFoundSetInternal newModel) throws ServoyException {
if (newModel == formModel || adjustingModel) {
// same or adjusting do nothing
return true;
}
ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
if (newModel != null && ((formTable == null && newModel.getTable() != null) || (formTable != null && !formTable.equals(newModel.getTable())))) {
throw new IllegalArgumentException(application.getI18NMessage("servoy.formPanel.error.wrongFoundsetTable", new Object[] { // $NON-NLS-1$
newModel.getTable() == null ? "NONE" : newModel.getTable().getName(), // $NON-NLS-1$
form.getTableName() }));
}
try {
IView view = getViewComponent();
if (view != null && view.isEditing()) {
// TODO if save fails don't set the newModel??
int stopped = application.getFoundSetManager().getEditRecordList().stopEditing(false);
if (stopped != ISaveConstants.STOPPED && stopped != ISaveConstants.AUTO_SAVE_BLOCKED) {
return false;
}
}
adjustingModel = true;
if (formModel != null) {
try {
((ISwingFoundSet) formModel).getSelectionModel().removeListSelectionListener(this);
((ISwingFoundSet) formModel).getSelectionModel().removeFormController(this);
((ISwingFoundSet) formModel).removeTableModelListener(this);
// to make sure all data is gc'ed
if (formModel instanceof FoundSet)
((FoundSet) formModel).flushAllCachedItems();
} catch (Exception ex) {
Debug.error(ex);
}
}
setFormModelInternal(newModel == null ? ((FoundSetManager) application.getFoundSetManager()).getEmptyFoundSet(this) : newModel);
if (formScope != null) {
// $NON-NLS-1$
formScope.putWithoutFireChange("foundset", formModel);
if (formScope.getPrototype() == null) {
formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
}
}
if (isFormVisible) {
((ISwingFoundSet) formModel).getSelectionModel().addListSelectionListener(this);
((ISwingFoundSet) formModel).getSelectionModel().addFormController(this);
((ISwingFoundSet) formModel).addTableModelListener(this);
if (// it may not yet exist
view != null) {
view.setModel(formModel);
}
// this was former a call to aggregateChange, but now does now unwanted parent traverse...
int[] idx = null;
if (getView() == RECORD_VIEW || getView() == LOCKED_RECORD_VIEW) {
int selIdx = formModel.getSelectedIndex();
if (selIdx != -1)
idx = new int[] { selIdx };
} else {
idx = formModel.getSelectedIndexes();
}
if (idx == null || idx.length == 0) {
refreshAllPartRenderers(new IRecordInternal[] { formModel.getPrototypeState() });
} else {
IRecordInternal[] row = new IRecordInternal[idx.length];
for (int i = 0; i < idx.length; i++) row[i] = formModel.getRecord(idx[i]);
refreshAllPartRenderers(row);
}
}
} finally {
adjustingModel = false;
}
return true;
}
Aggregations