Commit 3ea62655 authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

execute js only after browser ready

parent 13062b95
package de.blumenbach_online.tglab.sammlungsdb.views;
import java.util.ArrayList;
import info.textgrid.lab.authn.RBACSession;
import info.textgrid.lab.core.model.TextGridObject;
......@@ -18,6 +20,7 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.progress.UIJob;
import de.blumenbach_online.tglab.sammlungsdb.Activator;
import de.blumenbach_online.tglab.sammlungsdb.preferences.PluginPreferencePage;
......@@ -25,7 +28,8 @@ import de.blumenbach_online.tglab.sammlungsdb.preferences.PluginPreferencePage;
public class SammlungsDbEditor extends EditorPart {
private Browser browser;
private boolean browserReady = false;
private boolean browserReady = false;
private ArrayList<UIJob> browserJobs = new ArrayList<UIJob>();
@Override
public void doSave(IProgressMonitor arg0) {
......@@ -60,11 +64,9 @@ public class SammlungsDbEditor extends EditorPart {
String uri = tgo.getURI().toString();
String contentType = tgo.getMetadata().getGeneric().getProvided().getFormat();
if(browserReady) {
System.out.println("u: " + uri + " - t: " + title + " - ct: " + contentType);
browser.execute("addTGObject('"+uri+"', '"+title+"', '"+contentType+"')");
}
this.setPartName(title);
scheduleJavascript("addTGObject('"+uri+"', '"+title+"', '"+contentType+"')");
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Error !", e);
......@@ -115,16 +117,44 @@ public class SammlungsDbEditor extends EditorPart {
//System.out.println("set sid to: " + sid);
browser.execute("setSid('"+sid+"')");
String user = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbUser_id, "", null);
String pw = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbPW_id, "", null);
String user = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbUser_id, "", null);
String pw = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbPW_id, "", null);
browser.execute("setAuth('"+user+"','"+pw+"')");
browserReady = true;
for(UIJob job : browserJobs) {
job.schedule();
}
}
});
}
/**
* execute javascript only is browser is ready, otherwise put it to joblist
* @param js
*/
public void scheduleJavascript(final String js) {
UIJob execjs = new UIJob("executing Javasscript"){
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
browser.execute(js);
return Status.OK_STATUS;
}
};
registerBrowserJob(execjs);
}
public void registerBrowserJob(UIJob job) {
if(browserReady) job.schedule();
else browserJobs.add(job);
}
@Override
public void setFocus() {
......
......@@ -68,8 +68,8 @@ public class SammlungsDbView extends ViewPart {
//System.out.println("set sid to: " + sid);
spBrowser.execute("setSid('"+sid+"')");
String user = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbUser_id, "", null);
String pw = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbPW_id, "", null);
String user = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbUser_id, "", null);
String pw = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbPW_id, "", null);
spBrowser.execute("setAuth('"+user+"','"+pw+"')");
browserReady = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment