Commit 1ca73384 authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

collect and execute javascript command issued before browser view was set up

parent 139c9c38
......@@ -39,7 +39,7 @@
commandId="info.textgrid.lab.sadepublish.showSadePublish">
</handler>
</extension>
<extension
<extension
point="org.eclipse.ui.commands">
<command
description="Publish selected Object to SADE"
......
......@@ -26,6 +26,10 @@ import info.textgrid.lab.authn.RBACSession;
import info.textgrid.lab.sadepublish.Activator;
import info.textgrid.lab.sadepublish.preferences.PluginPreferencePage;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
......@@ -40,11 +44,12 @@ public class SadePublishView extends ViewPart {
private Browser spBrowser;
private boolean browserReady = false;
Queue<String> jsExecutions = new LinkedList<String>(); // queue to for JavaScript commands to execute which where issued before browserReady
@Override
public void createPartControl(Composite parent) {
try {
//spBrowser = new Browser(parent, SWT.MOZILLA);
spBrowser = new Browser(parent, SWT.NONE);
} catch (SWTError e) {
System.out.println("Could not instantiate Browserview " + e.getMessage());
......@@ -60,39 +65,46 @@ public class SadePublishView extends ViewPart {
spBrowser.setUrl(url);
spBrowser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent arg0) {}
@Override
public void completed(ProgressEvent arg0) {
String sid = RBACSession.getInstance().getSID(false);
//System.out.println("set sid to: " + sid);
spBrowser.execute("setSid('"+sid+"')");
String user = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.sadeUser_id, "", null);
String pw = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.sadePW_id, "", null);
String user = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.sadeUser_id, "", null);
String pw = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.sadePW_id, "", null);
spBrowser.execute("setAuth('"+user+"','"+pw+"')");
browserReady = true;
// execute JavaScript commands which where collected before browser was ready
Iterator<String> it = jsExecutions.iterator();
while(it.hasNext()) {
String command = it.next();
spBrowser.execute(command);
it.remove();
}
}
});
}
public void addTextGridObject(String uri, String title, String contentType) {
System.out.println("before browserready: u: " + uri + " - t: " + title + " - ct: " + contentType);
// Drag from Navigator generates a title like "TITLE (URI)".
// While i think the Navigator is wrong, this is the place where i can
// ensure that both methods are conform.
String command = "addTGObject('"+uri+"', '"+title + " ("+uri+")"+"', '"+contentType+"')";
if(browserReady) {
System.out.println("u: " + uri + " - t: " + title + " - ct: " + contentType);
spBrowser.execute("addTGObject('"+uri+"', '"+title + " ("+uri+")"+"', '"+contentType+"')");
spBrowser.execute(command);
} else {
jsExecutions.add(command);
}
}
/**
* Passing the focus request to the viewer's control.
*/
@Override
public void setFocus() {
//viewer.getControl().setFocus();
}
......
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