use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class TemplateGenerator method getFormHTMLAndCSS.
public static Pair<String, String> getFormHTMLAndCSS(Solution solution, Form form, IServiceProvider sp, String formInstanceName) throws RepositoryException, RemoteException {
if (form == null)
return null;
final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
boolean enableAnchoring = sp != null ? Utils.getAsBoolean(sp.getRuntimeProperties().get("enableAnchors")) : Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.webclient.enableAnchors", Boolean.TRUE.toString()));
String overriddenStyleName = null;
Pair<String, ArrayList<Pair<String, String>>> retval = formCache.getFormAndCssPair(form, formInstanceName, overriddenStyleName, repository);
Form f = form;
FlattenedSolution fsToClose = null;
try {
if (retval == null) {
if (f.getExtendsID() > 0) {
FlattenedSolution fs = sp == null ? null : sp.getFlattenedSolution();
if (fs == null) {
try {
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
fsToClose = fs = new FlattenedSolution(solution.getSolutionMetaData(), new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return repository;
}
});
} catch (RepositoryException e) {
Debug.error("Couldn't create flattened form for the template generator", e);
}
}
f = fs.getFlattenedForm(f);
if (f == null) {
Debug.log("TemplateGenerator couldn't get a FlattenedForm for " + form + ", solution closed?");
f = form;
}
}
StringBuffer html = new StringBuffer();
TextualCSS css = new TextualCSS();
IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(sp, solution, f, formInstanceName);
int viewType = layoutProvider.getViewType();
layoutProvider.renderOpenFormHTML(html, css);
int startY = 0;
Iterator<Part> parts = f.getParts();
while (parts.hasNext()) {
Part part = parts.next();
int endY = part.getHeight();
if (Part.rendersOnlyInPrint(part.getPartType())) {
startY = part.getHeight();
// is never shown (=printing only)
continue;
}
Color bgColor = ComponentFactory.getPartBackground(sp, part, f);
if (part.getPartType() == Part.BODY && (viewType == FormController.TABLE_VIEW || viewType == FormController.LOCKED_TABLE_VIEW || viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW)) {
layoutProvider.renderOpenTableViewHTML(html, css, part);
// tableview == bodypart
createCellBasedView(f, f, html, css, layoutProvider.needsHeaders(), startY, endY, bgColor, sp, viewType, enableAnchoring, startY, endY);
layoutProvider.renderCloseTableViewHTML(html);
} else {
layoutProvider.renderOpenPartHTML(html, css, part);
placePartElements(f, startY, endY, html, css, bgColor, enableAnchoring, sp);
layoutProvider.renderClosePartHTML(html, part);
}
startY = part.getHeight();
}
layoutProvider.renderCloseFormHTML(html);
retval = new Pair<String, ArrayList<Pair<String, String>>>(html.toString(), css.getAsSelectorValuePairs());
formCache.putFormAndCssPair(form, formInstanceName, overriddenStyleName, repository, retval);
}
Map<String, String> formIDToMarkupIDMap = null;
if (sp instanceof IApplication) {
Map runtimeProps = sp.getRuntimeProperties();
Map<WebForm, Map<String, String>> clientFormsIDToMarkupIDMap = (Map<WebForm, Map<String, String>>) runtimeProps.get("WebFormIDToMarkupIDCache");
if (clientFormsIDToMarkupIDMap == null) {
clientFormsIDToMarkupIDMap = new WeakHashMap<WebForm, Map<String, String>>();
runtimeProps.put("WebFormIDToMarkupIDCache", clientFormsIDToMarkupIDMap);
}
IForm wfc = ((IApplication) sp).getFormManager().getForm(formInstanceName);
if (wfc instanceof FormController) {
IFormUIInternal wf = ((FormController) wfc).getFormUI();
if (wf instanceof WebForm) {
if (!((WebForm) wf).isUIRecreated())
formIDToMarkupIDMap = clientFormsIDToMarkupIDMap.get(wf);
if (formIDToMarkupIDMap == null) {
ArrayList<Pair<String, String>> formCSS = retval.getRight();
ArrayList<String> selectors = new ArrayList<String>(formCSS.size());
for (Pair<String, String> formCSSEntry : formCSS) selectors.add(formCSSEntry.getLeft());
formIDToMarkupIDMap = getWebFormIDToMarkupIDMap((WebForm) wf, selectors);
clientFormsIDToMarkupIDMap.put((WebForm) wf, formIDToMarkupIDMap);
}
}
}
}
String webFormCSS = getWebFormCSS(retval.getRight(), formIDToMarkupIDMap);
// string the formcss/solutionname/ out of the url.
webFormCSS = StripHTMLTagsConverter.convertMediaReferences(webFormCSS, solution.getName(), new ResourceReference("media"), "", false).toString();
return new Pair<String, String>(retval.getLeft(), webFormCSS);
} finally {
if (fsToClose != null) {
fsToClose.close(null);
}
}
}
use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class WebAccordionPanel method notifyResized.
public void notifyResized() {
if (currentForm != null && currentForm.isReady()) {
WebForm webForm = currentForm.getWebForm();
FormController controller = webForm.getController();
if (controller != null && webForm.isFormWidthHeightChanged()) {
controller.notifyResized();
webForm.clearFormWidthHeightChangedFlag();
if (// $NON-NLS-1$
Utils.getAsBoolean(application.getRuntimeProperties().get("enableAnchors"))) {
scriptable.getChangesRecorder().setChanged();
}
}
}
}
use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class WebDataRendererFactory method reapplyTabSequence.
/**
* This method is the real tabIndex calculator for all forms in containers. When a container form is made visible, tabIndexes must be recalculated.
* Having the tab sequence tree, the tab sequence order is the preorder traversal of the tree. All elements after modified container in tab sequence order will be recalculated.
* A small gap for each container is used, so that chances that tabIndex should be changed when visible tab is different are smaller.
* Browsers cannot deal with really big numbers of tabIndex (maximum is around 32k). WebCellBasedView is also a special case, some bigger gap is used for that (it will fill tabIndexes itself).
*/
public void reapplyTabSequence(IFormUIInternal containerImpl, int delta) {
WebForm wf = (WebForm) containerImpl;
WebForm currentForm = wf;
IWebFormContainer currentTabPanel = null;
boolean ready = false;
int counter = delta + 1;
do {
List<Component> existingTabSequence = currentForm.getTabSeqComponents();
Iterator<Component> iter = existingTabSequence.iterator();
if (!containerImpl.equals(currentForm)) {
while (iter.hasNext()) {
Component c = iter.next();
if (c.equals(currentTabPanel)) {
if (delta >= 0) {
counter = getContainerGapIndex(counter, currentTabPanel.getTabSequenceIndex());
}
break;
}
}
}
while (iter.hasNext()) {
Component comp = iter.next();
if (comp instanceof IWebFormContainer) {
counter = goDownContainer((IWebFormContainer) comp, delta >= 0 ? counter : ISupportWebTabSeq.SKIP);
} else if (comp instanceof WebCellBasedView) {
WebCellBasedView tableView = (WebCellBasedView) comp;
tableView.setTabSequenceIndex(delta >= 0 ? counter : ISupportWebTabSeq.SKIP);
counter += MAXIMUM_TAB_INDEXES_ON_TABLEVIEW;
TabIndexHelper.setUpTabIndexAttributeModifier(comp, ISupportWebTabSeq.SKIP);
} else {
if (delta >= 0) {
counter = setMaxTabIndex(comp, counter);
} else {
TabIndexHelper.setUpTabIndexAttributeModifier(comp, ISupportWebTabSeq.SKIP);
}
}
}
if (delta >= 0) {
counter = getContainerGapIndex(counter, delta);
}
MarkupContainer parent = currentForm.getParent();
while ((parent != null) && !(parent instanceof IWebFormContainer)) parent = parent.getParent();
if (parent != null) {
if (parent instanceof WebSplitPane) {
((WebSplitPane) parent).setFormLastTabIndex(currentForm, counter - 1);
}
currentTabPanel = (IWebFormContainer) parent;
MarkupContainer tabParent = ((Component) currentTabPanel).getParent();
while ((tabParent != null) && !(tabParent instanceof WebForm)) tabParent = tabParent.getParent();
if (tabParent != null) {
currentForm = (WebForm) tabParent;
} else {
ready = true;
}
} else {
ready = true;
}
} while (!ready);
}
use of com.servoy.j2db.server.headlessclient.WebForm 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.server.headlessclient.WebForm in project servoy-client by Servoy.
the class WebDataHtmlView method onSubmit.
/**
* @see com.servoy.j2db.server.headlessclient.dataui.WebBaseSubmitLink#onSubmit()
*/
@Override
public void onSubmit() {
super.onSubmit();
String scriptName = RequestCycle.get().getRequest().getParameter(getInputName());
WebForm wf = findParent(WebForm.class);
if (wf != null) {
wf.getController().eval(scriptName);
}
}
Aggregations