use of com.servoy.j2db.FormController in project servoy-client by Servoy.
the class FormCssResource method getResourceStream.
/**
* @see org.apache.wicket.Resource#getResourceStream()
*/
@Override
public IResourceStream getResourceStream() {
String css = "";
ValueMap params = getParameters();
Long time = null;
if (params.size() == 1) {
Iterator iterator = params.entrySet().iterator();
if (iterator.hasNext()) {
Map.Entry entry = (Entry) iterator.next();
String solutionName = (String) entry.getKey();
Pair<String, Long> filterTime = filterTime((String) entry.getValue());
String formInstanceName = filterTime.getLeft();
time = filterTime.getRight();
// $NON-NLS-1$
String solutionAndForm = solutionName + "/" + formInstanceName;
// $NON-NLS-1$
String templateDir = "default";
IServiceProvider sp = null;
Solution solution = null;
Form form = null;
if (Session.exists()) {
sp = WebClientSession.get().getWebClient();
if (sp != null) {
IForm fc = ((WebClient) sp).getFormManager().getForm(formInstanceName);
if (fc instanceof FormController) {
FlattenedSolution clientSolution = sp.getFlattenedSolution();
form = clientSolution.getForm(((FormController) fc).getForm().getName());
}
}
templateDir = WebClientSession.get().getTemplateDirectoryName();
}
final String fullpath = "/servoy-webclient/templates/" + templateDir + "/" + solutionAndForm + ".css";
try {
URL url = context.getResource(fullpath);
if (url != null) {
return new NullUrlResourceStream(url);
}
} catch (Exception e) {
Debug.error(e);
}
try {
IApplicationServerSingleton as = ApplicationServerRegistry.get();
RootObjectMetaData sd = as.getLocalRepository().getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
if (sd != null) {
solution = (Solution) as.getLocalRepository().getActiveRootObject(sd.getRootObjectId());
if (form == null) {
form = solution.getForm(formInstanceName);
}
}
if (form != null) {
Pair<String, String> formHTMLAndCSS = TemplateGenerator.getFormHTMLAndCSS(solution, form, sp, formInstanceName);
css = formHTMLAndCSS.getRight();
}
} catch (Exception e) {
Debug.error(e);
}
}
}
// $NON-NLS-1$
StringResourceStream stream = new StringResourceStream(css, "text/css");
stream.setLastModified(time != null ? Time.valueOf(time.longValue()) : null);
return stream;
}
use of com.servoy.j2db.FormController 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.FormController 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.FormController in project servoy-client by Servoy.
the class WebAccordionPanel method showFoundSet.
protected void showFoundSet(WebTabFormLookup flp, IRecordInternal parentState, List<SortColumn> sort) {
deregisterSelectionListeners();
if (!flp.isReady())
return;
FormController fp = flp.getWebForm().getController();
if (fp != null && flp.getRelationName() != null) {
IFoundSetInternal relatedFoundset = parentState == null ? null : parentState.getRelatedFoundSet(flp.getRelationName(), sort);
registerSelectionListeners(parentState, flp.getRelationName());
fp.loadData(relatedFoundset, null);
}
ITagResolver resolver = getTagResolver(parentState);
// refresh tab text
for (int i = 0; i < allTabs.size(); i++) {
WebTabHolder element = allTabs.get(i);
if (element.getPanel() == flp) {
element.refreshTagStrings(resolver);
break;
}
}
}
use of com.servoy.j2db.FormController in project servoy-client by Servoy.
the class WebAccordionPanel method notifyVisible.
public void notifyVisible(boolean visible, List<Runnable> invokeLaterRunnables) {
if (currentForm == null && allTabs.size() > 0) {
WebTabHolder holder = allTabs.get(0);
setCurrentForm(holder.getPanel(), -1, invokeLaterRunnables);
}
if (currentForm != null) {
FormController controller = currentForm.getWebForm().getController();
// this is not needed when closing
if (visible && parentData != null) {
showFoundSet(currentForm, parentData, controller.getDefaultSortColumns());
// Test if current one is there
if (currentForm.isReady()) {
addCurrentFormComponent();
recomputeTabSequence();
}
}
controller.notifyVisible(visible, invokeLaterRunnables);
}
}
Aggregations