Skip to main content



      Home
Home » Newcomers » Newcomers » Example of callback
Example of callback [message #200784] Wed, 21 March 2007 07:57 Go to next message
Eclipse UserFriend
Originally posted by: mukerji.nita.gmail.com

I have Eclipse SDK 3.2.1 Linux.I have used Multi Page Editor
Template to generate a editor plugin.I have a text file open in this
editor.
From a menu item I want to callback an executable code and
provide the textfile that is open in the editor, as input to the executable
code.Kindly provide some examples.
Re: Example of callback [message #200830 is a reply to message #200784] Wed, 21 March 2007 09:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Nita,

Maybe the PDE popup menu example will help. When you create a new
plugin project, that's one of the templates you can use. Otherwise, I
suggest searching Eclipse for articles or looking at Eclipse source code
for examples.


Nita wrote:
> I have Eclipse SDK 3.2.1 Linux.I have used Multi Page Editor
> Template to generate a editor plugin.I have a text file open in this
> editor.
> From a menu item I want to callback an executable code and
> provide the textfile that is open in the editor, as input to the
> executable
> code.Kindly provide some examples.
>
Re: Example of callback [message #200846 is a reply to message #200784] Wed, 21 March 2007 10:11 Go to previous message
Eclipse UserFriend
Hi Nita,

The code below illustrates an Action called on the contents of an Editor.

This code uses an IRunnableWithProgress because it makes a long running
call to a server (to send encrypted mail). You could replace this with
a simple call to your "callback".

Hope this helps.

Charlie









/**
* Copyright (c) 2006, Charles Kelly; All rights reserved
*/
package com.charleskelly.mail.ui.actions.send;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.charleskelly.client_side_logger.ClientSideLogger;
import com.charleskelly.mail.model.VmHolder;
import com.charleskelly.mail.ui.editors.MailEditor;
import com.charleskelly.mail.ui.editors.editor_inputs.MailEditorInp ut;
import com.charleskelly.mail.ui.subactions.send.SendMailSubAction;

public class SendMailAction extends Action
{
private final static String ID =
"com.charleskelly.mail.ui.actions.send.SendMailAction";
private static final String pluginID = "com.charleskelly.mail.ui";
private static final String classID = ID;
//////////////////////////////////////////////////////////// ////////////
private final IWorkbenchWindow iWorkbenchWindow;

@SuppressWarnings("unused")
// private IStructuredSelection iStructuredSelection;
//////////////////////////////////////////////////////////// ////////////////

public SendMailAction (IWorkbenchWindow iWorkbenchWindow)
{
this.iWorkbenchWindow = iWorkbenchWindow;
this.setId(ID);
this.setText("&Send mail");
this.setToolTipText("Request mail sending services from Mail Sending
Provider");

ImageDescriptor imageDescriptor =
AbstractUIPlugin.imageDescriptorFromPlugin("com.charleskelly.mail.ui ",
"icons/send.jpg");
this.setImageDescriptor(imageDescriptor);
}// public EditCKMailAction (IWorkbenchWindow iWorkbenchWindow)
//////////////////////////////////////////////////////////// ////////////////
public void run()
{

try
{
IEditorPart iEditorPart =
iWorkbenchWindow.getActivePage().getActiveEditor();
MailEditor mailEditor = (MailEditor) iEditorPart;
mailEditor.doSave(null);
VmHolder vmHolder = mailEditor.getVmHolder();
VmHolder newVmHolder = vmHolder.makeCopy();
//////////////////////////////////////////////////////////// ////
MailEditorInput mailEditorInput = mailEditor.getMailEditorInput();
SendMailSubAction sendMailSubAction = new SendMailSubAction
(newVmHolder, mailEditorInput);
IRunnableWithProgress iRunnableWithProgress = sendMailSubAction;
ProgressMonitorDialog progressMonitorDialog = new
ProgressMonitorDialog (Display.getCurrent().getActiveShell() );

boolean separateThread = false;
boolean cancelable = true;
progressMonitorDialog.run (separateThread, cancelable,
iRunnableWithProgress);

mailEditor.close(false);
}// try
catch (InvocationTargetException ite)
{
ClientSideLogger.logError (pluginID, classID, "run()",
ite.toString(), ite);
MessageDialog.openError(
Display.getCurrent().getActiveShell(),
"SendMailAction",
ite.toString() );
}// catch (InvocationTargetException e)
catch (InterruptedException ie)
{
ClientSideLogger.logError (pluginID, classID, "run()", ie.toString(),
ie);
}// catch (InterruptedException e)
catch (Exception e)
{
ClientSideLogger.logError (pluginID, classID, "run()", e.toString(), e);
MessageDialog.openError(
Display.getCurrent().getActiveShell(),
"ScheduleDisbursementSubAction",
e.toString() );
}// catch (Exception e)
}// public void run()
//////////////////////////////////////////////////////////// ////////////////

public void dispose()
{

}// public void dispose()
//////////////////////////////////////////////////////////// ////////////////
public static String getID()
{
return ID;
}// public static String getID()
//////////////////////////////////////////////////////////// ////////////////

}// public class EditCKMailAction extends Action implements
ISelectionListener, IWorkbenchAction



Nita wrote:
> I have Eclipse SDK 3.2.1 Linux.I have used Multi Page Editor
> Template to generate a editor plugin.I have a text file open in this
> editor.
> From a menu item I want to callback an executable code and
> provide the textfile that is open in the editor, as input to the executable
> code.Kindly provide some examples.
>
Previous Topic:Does Eclipse supports Apache axis2 ?
Next Topic:How tthe error message in eclipse are internationalized?
Goto Forum:
  


Current Time: Sat Jun 07 20:07:19 EDT 2025

Powered by FUDForum. Page generated in 0.08535 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top