use of com.servoy.j2db.FormController in project servoy-client by Servoy.
the class WebSplitPane method setForm.
public boolean setForm(boolean bLeftForm, Object form, Object relation) {
FormController f = null;
String fName = null;
boolean readOnly = false;
if (form instanceof FormController) {
f = (FormController) form;
readOnly = f.isReadOnly();
}
if (form instanceof BasicFormController.JSForm) {
f = (FormController) ((BasicFormController.JSForm) form).getFormPanel();
readOnly = f.isReadOnly();
}
if (f != null)
fName = f.getName();
if (form instanceof String)
fName = (String) form;
if (fName != null) {
String tabname = fName;
RelatedFoundSet relatedFs = null;
String relationName = null;
if (relation instanceof RelatedFoundSet) {
relatedFs = (RelatedFoundSet) relation;
} else if (relation instanceof String) {
relationName = (String) relation;
}
if (relatedFs != null) {
relationName = relatedFs.getRelationName();
if (f != null && !relatedFs.getDataSource().equals(f.getDataSource())) {
return false;
}
// TODO do this check to check if the parent table has this relation? How to get the parent table
// Table parentTable = null;
// application.getSolution().getRelations(Solution.SOLUTION+Solution.MODULES, parentTable, true, false);
}
IFormLookupPanel replacedForm = bLeftForm ? getLeftForm() : getRightForm();
if (replacedForm != null) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
boolean bNotifyVisibleForm = notifyVisibleForm(false, bLeftForm ? 0 : 1, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (!bNotifyVisibleForm)
return false;
}
WebTabFormLookup flp = (WebTabFormLookup) createFormLookupPanel(tabname, relationName, fName);
if (f != null)
flp.setReadOnly(readOnly);
if (bLeftForm)
setLeftForm(flp);
else
setRightForm(flp);
if (relatedFs != null) {
FormController fp = flp.getWebForm().getController();
if (fp != null && flp.getRelationName() != null && flp.getRelationName().equals(relationName)) {
fp.loadData(relatedFs, null);
}
}
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
boolean bNotifyVisibleForm = notifyVisibleForm(true, bLeftForm ? 0 : 1, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (bNotifyVisibleForm) {
paneChanged[bLeftForm ? 0 : 1] = true;
}
return bNotifyVisibleForm;
} else if (form == null) {
IFormLookupPanel replacedForm = bLeftForm ? getLeftForm() : getRightForm();
if (replacedForm != null) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
boolean bNotifyVisibleForm = notifyVisibleForm(false, bLeftForm ? 0 : 1, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (!bNotifyVisibleForm)
return false;
}
splitComponents[bLeftForm ? 0 : 1].replace(new Label("webform", new Model<String>("")));
webTabs[bLeftForm ? 0 : 1] = null;
paneChanged[bLeftForm ? 0 : 1] = true;
return true;
}
return false;
}
use of com.servoy.j2db.FormController in project servoy-client by Servoy.
the class WebTabFormLookup method notifyVisible.
public boolean notifyVisible(boolean b, List invokeLaterRunnables) {
if (isReady()) {
IFormUIInternal ui = webForm;
FormController child = ui.getController();
return child.notifyVisible(b, invokeLaterRunnables);
}
return true;
}
use of com.servoy.j2db.FormController in project servoy-client by Servoy.
the class WebTabFormLookup method getWebForm.
private WebForm getWebForm(boolean removeFromParent) {
if (webForm != null && webForm.isDestroyed()) {
webForm = null;
}
if (webForm == null) {
FormManager fm = (FormManager) application.getFormManager();
FormController fc = fm.getFormController(formName, this);
if (fc == null) {
fc = fm.leaseFormPanel(formName);
}
if (fc != null) {
// delegate readOnly, really set it once from the form manager state
fc.setReadOnly(fm.isFormReadOnly(formName));
webForm = (WebForm) fc.getFormUI();
if (removeFromParent && webForm.getParent() != null && webForm.getParent() != parent) {
webForm.remove();
}
}
}
return webForm;
}
use of com.servoy.j2db.FormController in project servoy-client by Servoy.
the class ComponentFactory method createGraphicalComponent.
private static IComponent createGraphicalComponent(IApplication application, Form form, GraphicalComponent label, IScriptExecuter el, IDataProviderLookup dataProviderLookup) {
int style_halign = -1;
int style_valign = -1;
int textTransform = 0;
int mediaid = 0;
Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, label, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
style_valign = ss.getVAlign(s);
style_halign = ss.getHAlign(s);
boolean parseMedia = true;
// anything else then then the css through the templategenerator is used. (See TemplateGenerator.createGraphicalComponentHTML)
if (application.getApplicationType() == IApplication.WEB_CLIENT) {
parseMedia = s.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()) == null && s.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()) == null;
}
if (parseMedia) {
Object mediaUrl = s.getValue(CSS.Attribute.BACKGROUND_IMAGE.toString());
if (mediaUrl != null && mediaUrl.toString() != null) {
String mediaUrlString = mediaUrl.toString();
int start = mediaUrlString.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
if (start != -1) {
String name = mediaUrlString.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
if (name.endsWith("')") || name.endsWith("\")"))
name = name.substring(0, name.length() - 2);
if (name.endsWith(")"))
name = name.substring(0, name.length() - 1);
Media media = application.getFlattenedSolution().getMedia(name);
if (media != null) {
mediaid = media.getID();
}
}
}
}
String transform = s.getValue(CSS.Attribute.TEXT_TRANSFORM.toString());
if (transform != null) {
if ("uppercase".equals(transform)) {
textTransform = ILabel.UPPERCASE;
} else if ("lowercase".equals(transform)) {
textTransform = ILabel.LOWERCASE;
} else if ("capitalize".equals(transform)) {
textTransform = ILabel.CAPITALIZE;
}
}
}
}
ILabel l;
AbstractRuntimeLabel<? extends ILabel> scriptable;
IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
if (ComponentFactory.isButton(label)) {
IButton button;
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptButton(jsChangeRecorder, application);
button = application.getItemFactory().createScriptButton((RuntimeScriptButton) scriptable, getWebID(form, label));
} else {
scriptable = new RuntimeDataButton(jsChangeRecorder, application);
button = application.getItemFactory().createDataButton((RuntimeDataButton) scriptable, getWebID(form, label));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) button).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) button).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) button).setNeedEntireState(label.getDisplaysTags());
}
((AbstractRuntimeButton<IButton>) scriptable).setComponent(button, label);
button.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
button.setRolloverIcon(label.getRolloverImageMediaID());
button.setRolloverEnabled(true);
} catch (Exception ex) {
Debug.error(ex);
}
}
l = button;
} else {
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptLabel(jsChangeRecorder, application);
l = application.getItemFactory().createScriptLabel((RuntimeScriptLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
} else {
scriptable = new RuntimeDataLabel(jsChangeRecorder, application);
l = application.getItemFactory().createDataLabel((RuntimeDataLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) l).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) l).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) l).setNeedEntireState(label.getDisplaysTags());
}
((AbstractHTMLSubmitRuntimeLabel<ILabel>) scriptable).setComponent(l, label);
l.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
l.setRolloverIcon(label.getRolloverImageMediaID());
} catch (Exception ex) {
Debug.error(ex);
}
}
}
String mnemonic = application.getI18NMessageIfPrefixed(label.getMnemonic());
if (mnemonic != null && mnemonic.length() > 0) {
l.setDisplayedMnemonic(mnemonic.charAt(0));
}
l.setTextTransform(textTransform);
if (el != null && (label.getOnActionMethodID() > 0 || label.getOnDoubleClickMethodID() > 0 || label.getOnRightClickMethodID() > 0)) {
l.addScriptExecuter(el);
if (label.getOnActionMethodID() > 0)
l.setActionCommand(Integer.toString(label.getOnActionMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onActionMethodID")));
if (label.getOnDoubleClickMethodID() > 0)
l.setDoubleClickCommand(Integer.toString(label.getOnDoubleClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onDoubleClickMethodID")));
if (label.getOnRightClickMethodID() > 0)
l.setRightClickCommand(Integer.toString(label.getOnRightClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onRightClickMethodID")));
}
if (label.getLabelFor() == null || (form.getView() != FormController.TABLE_VIEW && form.getView() != FormController.LOCKED_TABLE_VIEW)) {
int onRenderMethodID = label.getOnRenderMethodID();
AbstractBase onRenderPersist = label;
if (onRenderMethodID <= 0) {
onRenderMethodID = form.getOnRenderMethodID();
onRenderPersist = form;
}
if (onRenderMethodID > 0) {
RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
IForm rendererForm = application.getFormManager().getForm(form.getName());
IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
}
}
l.setRotation(label.getRotation());
l.setFocusPainted(label.getShowFocus());
l.setCursor(Cursor.getPredefinedCursor(label.getRolloverCursor()));
try {
int halign = label.getHorizontalAlignment();
if (halign != -1) {
l.setHorizontalAlignment(halign);
} else if (style_halign != -1) {
l.setHorizontalAlignment(style_halign);
}
} catch (RuntimeException e) {
// just ignore...Debug.error(e);
}
int valign = label.getVerticalAlignment();
if (valign != -1) {
l.setVerticalAlignment(valign);
} else if (style_valign != -1) {
l.setVerticalAlignment(style_valign);
}
try {
if (!label.getDisplaysTags()) {
l.setText(application.getI18NMessageIfPrefixed(label.getText()));
}
} catch (RuntimeException e1) {
// ignore
}
l.setToolTipText(application.getI18NMessageIfPrefixed(label.getToolTipText()));
if (label.getImageMediaID() > 0) {
try {
l.setMediaIcon(label.getImageMediaID());
} catch (Exception e) {
Debug.error(e);
}
} else if (mediaid > 0) {
try {
l.setMediaIcon(mediaid);
} catch (Exception e) {
Debug.error(e);
}
}
if (label.getDataProviderID() != null) {
scriptable.setComponentFormat(ComponentFormat.getComponentFormat(label.getFormat(), label.getDataProviderID(), dataProviderLookup, application));
}
applyBasicComponentProperties(application, l, label, styleInfo);
Border border = null;
Insets insets = null;
if (label.getBorderType() != null) {
border = ComponentFactoryHelper.createBorder(label.getBorderType());
}
if (label.getMargin() != null) {
insets = label.getMargin();
}
if (styleInfo != null && (border == null || insets == null)) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (border == null && ss.hasBorder(s)) {
border = ss.getBorder(s);
}
if (insets == null && ss.hasMargin(s)) {
insets = ss.getMargin(s);
}
}
}
if (border != null && insets != null) {
l.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)));
} else if (border == null && insets != null && l instanceof IButton) {
((IButton) l).setMargin(insets);
} else // supports setMargin, then fake the margins through empty border. (issue 166391)
if (border == null && insets != null) {
l.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
}
if (l instanceof IAnchoredComponent) {
((IAnchoredComponent) l).setAnchors(label.getAnchors());
}
return l;
}
use of com.servoy.j2db.FormController 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;
}
Aggregations