use of com.servoy.j2db.scripting.InstanceJavaMembers in project servoy-client by Servoy.
the class FormManager method showFormInMainPanel.
// show a form in the main panel
public FormController showFormInMainPanel(final String formName, final IMainContainer container, final String title, final boolean closeAll, final String dialogName) {
if (loginForm != null && loginForm.getName() != formName) {
// not allowed to leave here...or show anything else than login form
return null;
}
// $NON-NLS-1$
if (formName == null)
throw new IllegalArgumentException(application.getI18NMessage("servoy.formManager.error.SettingVoidForm"));
FormController currentMainShowingForm = null;
if (currentContainer != null) {
currentMainShowingForm = container.getController();
}
boolean containerSwitch = container != currentContainer;
if (currentMainShowingForm != null && formName.equals(currentMainShowingForm.getName()) && !containerSwitch && !design)
return leaseFormPanel(currentMainShowingForm.getName());
final Form f = possibleForms.get(formName);
if (f == null) {
return null;
}
try {
int access = application.getFlattenedSolution().getSecurityAccess(f.getUUID(), f.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (access != -1) {
boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
if (!b_visible) {
application.invokeLater(new Runnable() {
public void run() {
// $NON-NLS-1$
application.reportWarningInStatus(application.getI18NMessage("servoy.formManager.warningAccessForm"));
}
});
return null;
}
}
// handle old panel
if (currentMainShowingForm != null) {
// leave forms in browse mode // TODO can this be set if notifyVisible returns false (current form is being kept)
if (!containerSwitch && application.getModeManager().getMode() != IModeManager.EDIT_MODE) {
application.getModeManager().setMode(IModeManager.EDIT_MODE);
}
FormController fp = leaseFormPanel(currentMainShowingForm.getName());
if (fp != null && !containerSwitch) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
boolean ok = fp.notifyVisible(false, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
// solution closed in onhide method of previous form?
if (application.getSolution() == null)
return null;
if (!ok) {
selectFormMenuItem(currentMainShowingForm.getForm());
return fp;
}
}
}
// set main
FormController tmpForm = currentMainShowingForm;
final FormController fp = leaseFormPanel(formName);
currentMainShowingForm = fp;
currentContainer = container;
if (fp != null) {
if (application.getCmdManager() instanceof ICmdManagerInternal) {
((ICmdManagerInternal) application.getCmdManager()).setCurrentUndoManager(fp.getUndoManager());
}
boolean isNewUser = checkAndUpdateFormUser(fp, container);
IFormUIInternal formUI = fp.getFormUI();
if (isNewUser) {
container.add(fp.getFormUI(), formName);
}
if (formUI != null && !formUI.isVisible())
formUI.setComponentVisible(true);
// this code must be below the checkAndUpdateUser because setFormController can already set the formui
currentContainer.setController(fp);
SolutionScope ss = application.getScriptEngine().getSolutionScope();
Context.enter();
try {
// $NON-NLS-1$
ss.put("currentcontroller", ss, new NativeJavaObject(ss, fp.initForJSUsage(), new InstanceJavaMembers(ss, JSForm.class)));
} finally {
Context.exit();
}
fp.setView(fp.getView());
fp.executeOnLoadMethod();
// test if solution is closed in the onload method.
if (application.getSolution() == null)
return null;
// correct script menu for this form
fillScriptMenu();
// if this is first show and we have to mimic the legacy 3.1 behavior of dialogs (show all in 1 window), allow 100 forms
if (!container.isVisible() && !closeAll) {
((FormManager) application.getFormManager()).getHistory(currentContainer).clear(100);
}
// add to history
getHistory(currentContainer).add(fp.getName());
// check for programatic change
selectFormMenuItem(f);
// show panel as main
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
fp.notifyVisible(true, invokeLaterRunnables);
// only enable command when it is the default container
// if (getMainContainer(null) == currentContainer)
// Command should rightly enabled for the forms
enableCmds(true);
final IMainContainer cachedContainer = currentContainer;
Runnable title_focus = new Runnable() {
public void run() {
FormController fc = cachedContainer.getController();
if (fc != null && fc == fp && application.getSolution() != null) {
// correct title
String titleText = title;
if (titleText == null)
titleText = f.getTitleText();
// $NON-NLS-1$
if (NO_TITLE_TEXT.equals(titleText))
titleText = "";
cachedContainer.setTitle(titleText);
cachedContainer.requestFocus();
}
}
};
if (isNewUser) {
final IMainContainer showContainer = currentContainer;
// to overcome paint problem in swing...
currentContainer.showBlankPanel();
invokeLaterRunnables.add(new Runnable() {
public void run() {
// only call show if it is still the right form.
FormController currentController = showContainer.getController();
if (currentController != null && fp.getName().equals(currentController.getName())) {
showContainer.show(fp.getName());
application.getRuntimeWindowManager().setCurrentWindowName(dialogName);
}
}
});
} else {
currentContainer.show(fp.getName());
application.getRuntimeWindowManager().setCurrentWindowName(dialogName);
}
invokeLaterRunnables.add(title_focus);
Utils.invokeLater(application, invokeLaterRunnables);
} else {
currentContainer.setController(null);
}
// $NON-NLS-1$
J2DBGlobals.firePropertyChange(this, "form", tmpForm, currentMainShowingForm);
return fp;
} catch (Exception e) {
Debug.error(e);
}
return null;
}
use of com.servoy.j2db.scripting.InstanceJavaMembers in project servoy-client by Servoy.
the class FormManager method setCurrentContainer.
/**
* @param mainContainer
*/
public void setCurrentContainer(IMainContainer mainContainer, String name) {
if (mainContainer != null) {
currentContainer = mainContainer;
if (name != null) {
// reset it in the containers (must be done for the webclient)
containers.put(name, mainContainer);
}
} else {
currentContainer = getMainContainer(null);
}
enableCmds(true);
FormController formController = currentContainer.getController();
if (formController != null) {
IExecutingEnviroment scriptEngine = application.getScriptEngine();
if (scriptEngine != null) {
SolutionScope ss = scriptEngine.getSolutionScope();
Context.enter();
try {
// $NON-NLS-1$
ss.put("currentcontroller", ss, new NativeJavaObject(ss, formController.initForJSUsage(), new InstanceJavaMembers(ss, JSForm.class)));
} finally {
Context.exit();
}
}
}
application.getRuntimeWindowManager().setCurrentWindowName(name);
}
Aggregations