Commit 2168befa authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

publish to sade from navigator

git-svn-id: https://textgridlab.org/svn/textgrid/trunk/lab/sadepublish@12642 7c539038-3410-0410-b1ec-0f2a7bf1c452
parent df3089ab
......@@ -29,7 +29,7 @@
<command
description="Open Sade Publish Perspective"
id="info.textgrid.lab.sadepublish.showSadePublish"
name="Sade Publish">
name="SADE Publish">
</command>
</extension>
<extension
......@@ -38,6 +38,21 @@
class="info.textgrid.lab.sadepublish.handlers.ShowSadePublishPerspectiveHandler"
commandId="info.textgrid.lab.sadepublish.showSadePublish">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
description="Publish selected Object to SADE"
id="info.textgrid.lab.sadepublish.publishSelected"
name="Publish to SADE">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="info.textgrid.lab.sadepublish.handlers.ShowSadePublishPerspectiveHandler"
commandId="info.textgrid.lab.sadepublish.publishSelected">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
......@@ -60,7 +75,7 @@
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="info.textgrid.lab.sadepublish.showSadePublish"
commandId="info.textgrid.lab.sadepublish.publishSelected"
icon="icons/025-publiziere-Objekt.gif"
style="push">
<visibleWhen
......
......@@ -21,15 +21,20 @@
*/
package info.textgrid.lab.sadepublish.handlers;
import info.textgrid.lab.core.model.TextGridObject;
import info.textgrid.lab.sadepublish.Activator;
import info.textgrid.lab.sadepublish.views.SadePublishView;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
......@@ -40,11 +45,7 @@ public class ShowSadePublishPerspectiveHandler extends AbstractHandler implemen
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
// test if command was called from navigator
ISelection selection = HandlerUtil.getCurrentSelection(event);
System.out.println("event from spublish" + event.getParameters());
// first reset the perspective...
IWorkbench wb = PlatformUI.getWorkbench();
wb.getActiveWorkbenchWindow().getActivePage().setPerspective(
......@@ -57,10 +58,41 @@ public class ShowSadePublishPerspectiveHandler extends AbstractHandler implemen
"info.textgrid.lab.sadepublish.perspectives.SadePublishPerspective",
PlatformUI.getWorkbench().getActiveWorkbenchWindow());
wb.getIntroManager().closeIntro(wb.getIntroManager().getIntro());
// test if command was called from navigator
if(event.getCommand().getId().equals("info.textgrid.lab.sadepublish.publishSelected")) {
System.out.println("publish selected");
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
for (Object obj : ((IStructuredSelection) selection).toList()){
if (obj instanceof IAdaptable) {
TextGridObject tgo = (TextGridObject) ((IAdaptable) obj)
.getAdapter(TextGridObject.class);
String title = tgo.getTitle();
String uri = tgo.getURI().toString();
String contentType = tgo.getMetadata().getGeneric().getProvided().getFormat();
((SadePublishView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.findView("info.textgrid.lab.sadepublish.views.SadePublishView")).addTextGridObject(uri, title, contentType);
}
}
}
}
} catch (WorkbenchException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Could not open Sade Publisher Perspective!", e);
Activator.getDefault().getLog().log(status);
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Error !", e);
Activator.getDefault().getLog().log(status);
}
return null;
}
......
......@@ -31,11 +31,15 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class PluginPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage{
public static String sadeUrl_id = "sade_instance_url";
public static String sadeUser_id = "sade_instance_user";
public static String sadePW_id = "sade_instance_pw";
@Override
protected void createFieldEditors() {
addField(new StringFieldEditor(sadeUrl_id, "URL for drag and drop to sade instance", getFieldEditorParent()));
addField(new StringFieldEditor(sadeUrl_id, "URL for SADE instance", getFieldEditorParent()));
addField(new StringFieldEditor(sadeUser_id, "Authorized user", getFieldEditorParent()));
addField(new StringFieldEditor(sadePW_id, "Password", getFieldEditorParent()));
}
......
......@@ -13,7 +13,6 @@ public class IsPublishableObject extends PropertyTester {
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
System.out.println("test content type");
if (receiver != null && receiver instanceof TGObjectReference) {
return isOK(AdapterUtils.getAdapter(receiver, TextGridObject.class));
}
......@@ -26,7 +25,9 @@ public class IsPublishableObject extends PropertyTester {
// reloadMetadata(tgo);
try {
contentTypeId = tgo.getContentTypeID();
if (contentTypeId.contains("tg.aggregation")) {
if (contentTypeId.contains("tg.aggregation")
|| contentTypeId.contains("xml")
|| contentTypeId.contains("image/")) {
return true;
}
} catch (CoreException e) {
......
......@@ -39,6 +39,7 @@ import org.eclipse.ui.part.ViewPart;
public class SadePublishView extends ViewPart {
private Browser spBrowser;
private boolean browserReady = false;
public void createPartControl(Composite parent) {
......@@ -65,11 +66,21 @@ public class SadePublishView extends ViewPart {
String sid = RBACSession.getInstance().getSID(false);
System.out.println("set sid to: " + sid);
spBrowser.execute("setSid('"+sid+"')");
browserReady = true;
}
});
}
public void addTextGridObject(String uri, String title, String contentType) {
System.out.println("before browserready: u: " + uri + " - t: " + title + " - ct: " + contentType);
if(browserReady) {
System.out.println("u: " + uri + " - t: " + title + " - ct: " + contentType);
spBrowser.execute("addTGObject('"+uri+"', '"+title+"', '"+contentType+"')");
}
}
/**
......
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