Commit 592e7615 authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

open new object after creation with wizard

parent b9e0a3f4
......@@ -12,6 +12,7 @@ Require-Bundle: org.eclipse.ui,
info.textgrid.lab.core.swtutils;bundle-version="1.0.2",
info.textgrid.lab.ui.core;bundle-version="1.0.1",
org.apache.cxf.bundle;bundle-version="2.5.5",
org.apache.servicemix.specs.jsr311-api-1.1.1;bundle-version="1.9.0"
org.apache.servicemix.specs.jsr311-api-1.1.1;bundle-version="1.9.0",
org.codehaus.jettison.jettison;bundle-version="1.3.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
......@@ -4,17 +4,29 @@ import info.textgrid.lab.authn.RBACSession;
import info.textgrid.lab.core.model.TextGridObject;
import info.textgrid.lab.ui.core.dialogs.INewObjectPreparator;
import info.textgrid.lab.ui.core.dialogs.ITextGridWizard;
import info.textgrid.lab.ui.core.dialogs.NewObjectWizard;
import info.textgrid.lab.ui.core.menus.OpenObjectService;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import javax.ws.rs.core.Response;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.ext.form.Form;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.json.JSONTokener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.progress.UIJob;
import de.blumenbach_online.tglab.sammlungsdb.preferences.PluginPreferencePage;
......@@ -39,57 +51,60 @@ public class Preparator implements INewObjectPreparator {
}
@Override
public boolean performFinish(TextGridObject textGridObject) {
public boolean performFinish(final TextGridObject textGridObject) {
try {
String url = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbUrl_id, "", null);
Form form = new Form();
form.set("tgSID", RBACSession.getInstance().getSID(false));
form.set("tgPID", textGridObject.getProject());
form.set("title", textGridObject.getTitle());
Response res = WebClient.create(url + "/db/create").form(form);
System.out.println(res.getStatus());
InputStream in = ((InputStream)res.getEntity());
IOUtils.copy(in, System.out);
new Job("creating sammlungsdbobject"){
@Override
protected IStatus run(IProgressMonitor arg0) {
try {
String url = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PluginPreferencePage.boldbUrl_id, "", null);
Form form = new Form();
form.set("tgSID", RBACSession.getInstance().getSID(false));
form.set("tgPID", textGridObject.getProject());
form.set("title", textGridObject.getTitle());
Response res = WebClient.create(url + "/db/create").form(form);
if(res.getStatus() != javax.ws.rs.core.Response.Status.CREATED.getStatusCode()) {
// TODO
}
InputStream in = (InputStream)res.getEntity();
JSONObject obj = new JSONObject(IOUtils.toString(in));
URI textgridUri = new URI((String)obj.get("@id"));
final TextGridObject tgo = TextGridObject.getInstance(textgridUri, true);
new UIJob("opening editor") {
@Override
public IStatus runInUIThread(IProgressMonitor arg0) {
OpenObjectService.getInstance().openObject(tgo, 0, false);
return Status.OK_STATUS;
}
}.schedule();
} catch (CoreException e) {
Activator.handleError(e, "error creating sammlungsdbobject");
} catch (IOException e) {
Activator.handleError(e, "error creating sammlungsdbobject");
} catch (JSONException e) {
Activator.handleError(e, "error creating sammlungsdbobject");
} catch (URISyntaxException e) {
Activator.handleError(e, "error creating sammlungsdbobject");
}
return Status.OK_STATUS;
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}.schedule();
return true;
/*
// TODO Auto-generated method stub
String inputString = "<RDF>bolbloblob</RDF>";
ByteArrayInputStream contentStream = null;
try {
contentStream = new ByteArrayInputStream(inputString.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// java.io.StringReader sReader = new StringReader("<TEI></TEI>");
// sReader.
try {
textGridObject.setInitialContent(contentStream, null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (wizard instanceof NewObjectWizard)
return ((NewObjectWizard) wizard).defaultPerformFinish("info.textgrid.lab.welcome.XMLEditorPerspective");
return true;
else
return false;*/
return false;
}
}
......@@ -24,6 +24,8 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.progress.UIJob;
......@@ -39,7 +41,6 @@ public class SammlungsDbEditor extends EditorPart {
@Override
public void doSave(IProgressMonitor arg0) {
// TODO Auto-generated method stub
scheduleJavascript("save();");
setDirty(false);
}
......@@ -54,6 +55,15 @@ public class SammlungsDbEditor extends EditorPart {
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
try {
PlatformUI.getWorkbench().showPerspective(
"de.blumenbach_online.tglab.sammlungsdb.perspectives.SammlungsDbPerspective",
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
Activator.handleError(e, "error opening sammlungsdbperspective");
}
TextGridObject tgo = (TextGridObject) input
.getAdapter(TextGridObject.class);
if (tgo != null) {
......@@ -106,17 +116,15 @@ public class SammlungsDbEditor extends EditorPart {
@Override
public boolean isSaveAsAllowed() {
// TODO Auto-generated method stub
return false;
}
@Override
public void createPartControl(Composite parent) {
try {
//spBrowser = new Browser(parent, SWT.MOZILLA);
browser = new Browser(parent, SWT.NONE);
} catch (SWTError e) {
System.out.println("Could not instantiate Browserview " + e.getMessage());
Activator.handleError(e, "Could not instantiate Browserview");
return;
}
......
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