use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class CompositeTransferHandler method dragOver.
/**
* @see java.awt.dnd.DropTargetListener#dragOver(DropTargetDragEvent)
*/
public void dragOver(DropTargetDragEvent e) {
dropTargetDragEvent = e;
int dropAction = e.getDropAction();
Component component = getDragComponent((JComponent) e.getDropTargetContext().getComponent());
if (actionSupported(dropAction) && component instanceof ICompositeDragNDrop) {
ICompositeDragNDrop dropComponent = (ICompositeDragNDrop) component;
Object dragSource = dropComponent.getDragSource(getEventXY(e));
// TODO: move this code out
IRecordInternal dragRecord = dropComponent instanceof IFormDataDragNDrop ? ((IFormDataDragNDrop) dropComponent).getDragRecord(getEventXY(e)) : null;
if (dragSource != lastDragSource || dragRecord != lastDragRecord) {
// simulate a drag enter now
dragEnter(e);
} else {
if (canImport) {
e.acceptDrag(dropAction);
} else {
e.rejectDrag();
}
}
} else {
e.rejectDrag();
}
dropTargetDragEvent = null;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class FormDataTransferHandler method createScriptEvent.
@Override
protected JSDNDEvent createScriptEvent(EventType type, ICompositeDragNDrop ddComponent, Object event) {
JSDNDEvent jsEvent = super.createScriptEvent(type, ddComponent, event);
if (ddComponent instanceof IFormDataDragNDrop) {
IFormDataDragNDrop formDataDDComponent = (IFormDataDragNDrop) ddComponent;
jsEvent.setFormName(formDataDDComponent.getDragFormName());
Point location = getEventXY(event);
if (location != null) {
Object dragSource = ddComponent.getDragSource(location);
if (dragSource instanceof IDataRenderer) {
IDataRenderer dr = (IDataRenderer) dragSource;
FormController fc = dr.getDataAdapterList().getFormController();
jsEvent.setSource(fc.getFormScope());
} else if (dragSource instanceof IComponent) {
jsEvent.setSource(dragSource);
if (dragSource != null) {
String name = ((IComponent) dragSource).getName();
if (name != null && name.startsWith(ComponentFactory.WEB_ID_PREFIX)) {
name = null;
}
jsEvent.setElementName(name);
}
}
IRecordInternal dragRecord = formDataDDComponent.getDragRecord(location);
if (dragRecord instanceof Record)
jsEvent.setRecord((Record) dragRecord);
}
}
return jsEvent;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class DataRendererDefinition method tempAddToParent.
void tempAddToParent(final RendererParentWrapper renderParent, final boolean fillWithData, final boolean doLayout, final boolean saveComponentBounds) {
try {
Runnable r = new Runnable() {
public void run() {
try {
if (!doLayout) {
// restore the bound to match exactly to the init phase
// (and no fields are cut in half due to different html render positions)
restoreSavedComponentBounds();
}
// data is needed to see how (much) to slide
if (fillWithData) {
IRecordInternal a_state = getState();
// lookup all field needed, so the are present in the state when needed for rendering
if (a_state != null)
renderer.getDataAdapterList().setRecord(a_state, true);
}
// always needed for correct layout of text-areas/mediafields
renderParent.add(renderer);
List<Component> invisibleComponents = new ArrayList<Component>();
Component[] comps = renderer.getComponents();
for (int i = 0; i < comps.length; i++) {
int slide = ISupportPrintSliding.NO_SLIDING;
Map componentsListToBeHandeld = renderer.getComponentsUsingSliding();
if (componentsListToBeHandeld != null && componentsListToBeHandeld.containsKey(comps[i])) {
slide = ((Integer) componentsListToBeHandeld.get(comps[i])).intValue();
}
// set components invisible if empty/null and should shrink
if (((slide & ISupportPrintSliding.SHRINK_HEIGHT) == ISupportPrintSliding.SHRINK_HEIGHT) && ((slide & ISupportPrintSliding.SHRINK_WIDTH) == ISupportPrintSliding.SHRINK_WIDTH) && comps[i] instanceof IDisplayData) {
boolean visible = !(((IDisplayData) comps[i]).getValueObject() == null || ((IDisplayData) comps[i]).getValueObject().toString().trim().length() == 0);
comps[i].setVisible(visible);
if (!visible) {
comps[i].setSize(0, 0);
invisibleComponents.add(comps[i]);
}
}
}
if (doLayout) {
renderer.invalidate();
renderer.validate();
for (Component invisibleComponent : invisibleComponents) {
invisibleComponent.setPreferredSize(new Dimension(0, 0));
}
// 1) do first
renderer.doLayout();
// 2) do second time, some times the after the fist time something is changed which causes stuff to render correctly
renderer.doLayout();
if (saveComponentBounds) {
// store the prefered sizes so we don't have todo layouting again (by adding / removing)
for (Component element : comps) {
bounds.put(element, new Rectangle(element.getBounds()));
}
}
for (Component invisibleComponent : invisibleComponents) {
invisibleComponent.setPreferredSize(null);
}
} else {
// for bounds change, important for html/text-areas
Iterator it = bounds.keySet().iterator();
while (it.hasNext()) {
Component c = (Component) it.next();
// relayouts the internals of html/text-areas
c.validate();
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
};
if (application.isEventDispatchThread()) {
r.run();
} else {
application.invokeAndWait(r);
}
} catch (Exception e) {
Debug.error(e);
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal 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.IRecordInternal in project servoy-client by Servoy.
the class DataLookupField method dependencyChanged.
public void dependencyChanged(IRecordInternal record) {
this.parentState = record;
if (list != null) {
Object o = getValue();
int index = -1;
if (dataProviderID != null && !ScopesUtils.isVariableScope(dataProviderID)) {
index = dataProviderID.lastIndexOf('.');
}
if (index == -1 || parentState == null || dataProviderID == null) {
list.fill(parentState);
} else {
IFoundSetInternal relatedFoundSet = parentState.getRelatedFoundSet(dataProviderID.substring(0, index));
if (relatedFoundSet == null) {
list.fill(parentState.getParentFoundSet().getPrototypeState());
} else if (relatedFoundSet.getSize() == 0) {
list.fill(relatedFoundSet.getPrototypeState());
} else {
IRecordInternal relatedRecord = relatedFoundSet.getRecord(relatedFoundSet.getSelectedIndex());
list.fill(relatedRecord);
}
}
if (editProvider != null) {
editProvider.setAdjusting(true);
}
try {
setValue(null);
setValue(o);
} finally {
if (editProvider != null) {
editProvider.setAdjusting(false);
}
}
}
}
Aggregations