use of com.servoy.j2db.smart.dataui.PortalComponent in project servoy-client by Servoy.
the class DataRendererDefinition method getPreferedBreakInternal.
private int getPreferedBreakInternal(RendererParentWrapper renderParent, int breakPosition) {
// the break position is relative to the remaining area to be used from the renderer; create the absolute breakk position for the renderer
Rectangle breakRect = new Rectangle(0, startYOrgin + breakPosition, getFullSize().width, 1);
// if we do not find a satisfactory break point, we use the first intersecting component desired break point
int firstConsideredBreak = -1;
// the last component that changed the preferred break point
Component lastComponent = null;
Iterator it = bounds.keySet().iterator();
while (it.hasNext()) {
Component component = (Component) it.next();
Rectangle cbounds = (Rectangle) bounds.get(component);
if (cbounds.intersects(breakRect) && component != lastComponent) {
Component comp = component;
int pos;
if (comp instanceof PortalComponent) {
Rectangle allocation = new Rectangle(cbounds);
PortalComponent pc = (PortalComponent) comp;
Insets ins2 = pc.getBorder().getBorderInsets(pc);
allocation.x += ins2.left;
allocation.y += ins2.top;
allocation.width -= ins2.right;
allocation.height -= ins2.bottom;
// give free space and receive preferred break relative to component
pos = pc.getPreferredBreak((startYOrgin + breakPosition - allocation.y));
if (pos != 0) {
// make preferred break relative to the renderer
pos = pos + allocation.y - startYOrgin;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.trace("PortalComponent " + cbounds + " requested break for " + breakPosition + " used break " + pos);
} else {
// no use breaking immediately after the border (no useful info)
pos = cbounds.getLocation().y - startYOrgin;
}
} else {
if (component instanceof IDelegate) {
comp = (Component) ((IDelegate) component).getDelegate();
}
if (comp instanceof JTextComponent) {
if (comp instanceof JTextField) {
// optimize, cannot break single line components, return the Y location
pos = cbounds.getLocation().y - startYOrgin;
} else {
JTextComponent tcomp = (JTextComponent) comp;
Rectangle allocation = new Rectangle(cbounds);
if (component instanceof JComponent) {
// ==scrollpane border
Insets ins2 = ((JComponent) component).getBorder().getBorderInsets(component);
if (ins2 != null) {
allocation.x += ins2.left;
allocation.y += ins2.top;
allocation.width -= ins2.right;
allocation.height -= ins2.bottom;
}
}
// ==margin
Insets ins2 = tcomp.getBorder().getBorderInsets(component);
if (ins2 != null) {
allocation.x += ins2.left;
allocation.y += ins2.top;
allocation.width -= ins2.right;
allocation.height -= ins2.bottom;
}
pos = searchDesiredBreakThroughViews((startYOrgin + breakPosition - allocation.y), 0, tcomp, 0, new Rectangle(0, 0, allocation.width, allocation.height));
if (pos != 0) {
// correct for location
pos = pos - startYOrgin + allocation.y;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.trace("JTextComponent " + cbounds + " requested break for " + breakPosition + " used break " + pos);
} else {
// no use breaking immediately after the border (no useful info)
pos = cbounds.getLocation().y - startYOrgin;
}
}
} else // for all other components
{
// optimize, better stop before comp
pos = cbounds.getLocation().y - startYOrgin;
}
}
// the current intersected component decided where it would want the page to break (pos); compare with the current break position
if (breakPosition != pos) {
// we have to modify the desired (page) break point
breakPosition = pos;
breakRect.y = startYOrgin + breakPosition;
// restart search for components that intersect the new considered break position
it = bounds.keySet().iterator();
if ((firstConsideredBreak == -1) && (breakPosition > 0)) {
firstConsideredBreak = breakPosition;
}
lastComponent = component;
}
if (breakPosition < 0) {
// the components that we would find below 0 from this part are already printed - so we did not find a convenient
break;
// break point in the given vertical space
}
}
}
if (breakPosition <= 0) {
// no satisfactory normal break position; returns the first found break position (that can be < 0 too if not found)
return firstConsideredBreak;
} else {
// found a good break position
return breakPosition;
}
}
use of com.servoy.j2db.smart.dataui.PortalComponent in project servoy-client by Servoy.
the class SwingForm method registerComponentsToScope.
private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Object[] compsRenderer, Component controller, Map<String, Object[]> hmChildrenJavaMembers) {
if (comps != null) {
for (int j = 0; j < comps.length; j++) {
Object comp = comps[j];
if (comp instanceof PortalComponent) {
PortalComponent portal = (PortalComponent) comp;
counter = registerComponentsToScope(fs, es, counter, portal.getEditorComponents(), portal.getRendererComponents(), portal, hmChildrenJavaMembers);
}
String name = null;
if (comp instanceof IComponent) {
name = ((IComponent) comp).getName();
} else if (comp instanceof Component) {
name = ((Component) comp).getName();
}
Object obj = comp;
if (comp instanceof InvisibleBean) {
obj = ((InvisibleBean) comp).getDelegate();
} else if (comp instanceof VisibleBean) {
obj = ((VisibleBean) comp).getDelegate();
}
String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
if (obj instanceof IScriptableProvider)
obj = ((IScriptableProvider) obj).getScriptObject();
IRuntimeComponent baseMethodsObj = null;
if (obj instanceof IRuntimeComponent) {
baseMethodsObj = (IRuntimeComponent) obj;
}
JavaMembers jm = ScriptObjectRegistry.getJavaMembers(obj.getClass(), ScriptableObject.getTopLevelScope(fs));
// $NON-NLS-1$
boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
if (groupName != null || named) {
Object obj2 = null;
if (compsRenderer != null) {
obj2 = compsRenderer[j];
if (obj2 instanceof InvisibleBean) {
obj2 = ((InvisibleBean) obj2).getDelegate();
}
}
try {
Scriptable s = null;
if (obj2 != null) {
if (obj2 instanceof IScriptableProvider)
obj2 = ((IScriptableProvider) obj2).getScriptObject();
NativeJavaObject s2 = new NativeJavaObject(fs, obj2, jm);
s = new TwoNativeJavaObject(fs, obj, s2, jm, controller);
// group properties have to be set to both
if (groupName != null && obj2 instanceof IRuntimeComponent) {
if (baseMethodsObj == null) {
baseMethodsObj = (IRuntimeComponent) obj2;
} else {
RuntimeGroup runtimeGroup = new RuntimeGroup(baseMethodsObj.getName());
runtimeGroup.addScriptBaseMethodsObj(baseMethodsObj);
runtimeGroup.addScriptBaseMethodsObj((IRuntimeComponent) obj2);
baseMethodsObj = runtimeGroup;
}
}
} else {
s = new NativeJavaObject(fs, obj, jm);
}
if (named) {
es.put(name, fs, s);
es.put(counter++, fs, s);
hmChildrenJavaMembers.put(name, new Object[] { jm, obj });
}
if (groupName != null) {
Object group = es.get(groupName, fs);
if (group == Scriptable.NOT_FOUND) {
group = new NativeJavaObject(fs, new RuntimeGroup(groupName), ScriptObjectRegistry.getJavaMembers(RuntimeGroup.class, ScriptableObject.getTopLevelScope(fs)));
es.put(groupName, fs, group);
es.put(counter++, fs, group);
}
if (baseMethodsObj != null && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj(baseMethodsObj);
}
}
} catch (Throwable ex) {
// incase classdefnot founds are thrown for beans,applets/plugins
Debug.error(ex);
}
}
}
}
return counter;
}
use of com.servoy.j2db.smart.dataui.PortalComponent in project servoy-client by Servoy.
the class TwoNativeJavaObject method get.
/*
* (non-Javadoc)
*
* @see org.mozilla.javascript.NativeJavaObject#get(java.lang.String, org.mozilla.javascript.Scriptable)
*/
@Override
public Object get(String name, Scriptable start) {
Object returnObject = null;
try {
returnObject = super.get(name, start);
} finally {
if (returnObject instanceof Function) {
// $NON-NLS-1$
if ("replaceSelectedText".equals(name))
return returnObject;
if (// $NON-NLS-1$
!"requestFocus".equals(name)) {
executingFunction = name;
TwoNativeJavaMethod methodWrapper = (TwoNativeJavaMethod) methodWrappers.get(returnObject);
if (methodWrapper == null) {
methodWrapper = new TwoNativeJavaMethod(javaObject2, (Function) returnObject, listView);
methodWrappers.put(returnObject, methodWrapper);
}
returnObject = methodWrapper;
} else {
final JComponent uiComponent = (JComponent) ((javaObject instanceof Wrapper) ? ((Wrapper) javaObject).unwrap() : javaObject);
if (listView instanceof TableView) {
final TableView tv = (TableView) listView;
tv.requestFocus();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final int selectedRow = tv.getSelectedRow();
for (int i = 0; i < tv.getColumnCount(); i++) {
if (((CellAdapter) tv.getCellEditor(selectedRow, i)).getEditor() == uiComponent) {
final int currentColumn = i;
tv.setColumnSelectionInterval(currentColumn, currentColumn);
tv.editCellAt(selectedRow, currentColumn);
break;
}
}
}
});
} else if (listView instanceof ListView) {
if (listView.isEnabled()) {
// if list is not enabled, all controls are disabled or readonly, no sense to start edit and request focus
// also when clicking and disabled we don't do anything
((ListView) listView).editCellAt((((ListView) listView).getSelectedIndex()));
uiComponent.requestFocus();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (!((ListView) listView).isEditing())
((ListView) listView).editCellAt((((ListView) listView).getSelectedIndex()));
}
});
}
} else if (listView instanceof PortalComponent) {
((PortalComponent) listView).editCellFor(uiComponent);
}
}
} else {
javaObject2.get(name, start);
}
}
return returnObject;
}
use of com.servoy.j2db.smart.dataui.PortalComponent in project servoy-client by Servoy.
the class TwoNativeJavaObject method unwrap.
@Override
public Object unwrap() {
// else debugger can block. If scripts will get its own thread this has to be invokeLater()
if (SwingUtilities.isEventDispatchThread()) {
// state. For example popupmenu tries to show an popup on the components location.
if (// $NON-NLS-1$ //$NON-NLS-2$
executingFunction == null || executingFunction.startsWith("getLocation") || executingFunction.startsWith("getWidth")) {
final JComponent uiComponent = (JComponent) ((javaObject instanceof Wrapper) ? ((Wrapper) javaObject).unwrap() : javaObject);
if (listView instanceof TableView) {
TableView tv = (TableView) listView;
TableCellEditor cellEditor = tv.getCellEditor();
if (!(cellEditor instanceof CellAdapter && ((CellAdapter) cellEditor).getEditor() == uiComponent)) {
int selectedRow = tv.getSelectedRow();
for (int i = 0; i < tv.getColumnCount(); i++) {
if (((CellAdapter) tv.getCellEditor(selectedRow, i)).getEditor() == uiComponent) {
TableModel tm = tv.getModel();
if (tm != null && tm.getRowCount() > 0) {
if (tv.isCellEditable(selectedRow, i)) {
tv.setColumnSelectionInterval(i, i);
tv.editCellAt(selectedRow, i);
} else {
// bounds can be modified even if readonly when moving columns
((Component) uiComponent).setBounds(tv.getCellRect(selectedRow, i, false));
}
}
break;
}
}
}
} else if (listView instanceof ListView) {
((ListView) listView).editCellAt((((ListView) listView).getSelectedIndex()));
} else if (listView instanceof PortalComponent) {
((PortalComponent) listView).editCellFor(uiComponent);
}
} else
executingFunction = null;
}
return super.unwrap();
}
Aggregations