Search in sources :

Example 1 with IInteractionContext

use of org.eclipse.mylyn.context.core.IInteractionContext in project ecf by eclipse.

the class Activator method handleChannelEvent.

public synchronized void handleChannelEvent(IChannelEvent e) {
    if (e instanceof IChannelMessageEvent) {
        IChannelMessageEvent msgEvent = (IChannelMessageEvent) e;
        byte[] data = msgEvent.getData();
        File file = new File(getStateLocation().toFile(), "incoming.xml.zip");
        try {
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(data);
            List tasks = TasksUiPlugin.getTaskListManager().getTaskListWriter().readTasks(file);
            final ITask task = (ITask) tasks.get(0);
            Set repositories = TasksUiPlugin.getTaskListManager().getTaskListWriter().readRepositories(file);
            TasksUiPlugin.getRepositoryManager().insertRepositories(repositories, TasksUiPlugin.getDefault().getRepositoriesFilePath());
            IInteractionContext context = ContextCore.getContextStore().importContext(task.getHandleIdentifier(), file);
            CompoundContextActivationContributionItem.enqueue(task, context);
            IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
            Shell aShell = null;
            for (int i = 0; i < windows.length; i++) {
                aShell = windows[i].getShell();
                if (aShell != null) {
                    break;
                }
            }
            if (aShell == null) {
                return;
            }
            final Shell shell = aShell;
            UIJob job = new UIJob("Notify of incoming shared task") {

                public IStatus runInUIThread(IProgressMonitor monitor) {
                    final IncomingSharedTaskNotificationPopup popup = new IncomingSharedTaskNotificationPopup(shell);
                    popup.setTask(task);
                    popup.open();
                    new // $NON-NLS-1$
                    UIJob(// $NON-NLS-1$
                    shell.getDisplay(), // $NON-NLS-1$
                    "Close Popup Job") {

                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            Shell shell = popup.getShell();
                            if (shell != null && !shell.isDisposed()) {
                                popup.close();
                            }
                            monitor.done();
                            return Status.OK_STATUS;
                        }
                    }.schedule(5000);
                    return Status.OK_STATUS;
                }
            };
            job.schedule();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            file.delete();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITask(org.eclipse.mylyn.tasks.core.ITask) Set(java.util.Set) Shell(org.eclipse.swt.widgets.Shell) IInteractionContext(org.eclipse.mylyn.context.core.IInteractionContext) FileOutputStream(java.io.FileOutputStream) UIJob(org.eclipse.ui.progress.UIJob) List(java.util.List) IChannelMessageEvent(org.eclipse.ecf.datashare.events.IChannelMessageEvent) File(java.io.File)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 List (java.util.List)1 Set (java.util.Set)1 IChannelMessageEvent (org.eclipse.ecf.datashare.events.IChannelMessageEvent)1 IInteractionContext (org.eclipse.mylyn.context.core.IInteractionContext)1 ITask (org.eclipse.mylyn.tasks.core.ITask)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 UIJob (org.eclipse.ui.progress.UIJob)1