MessageBox doesnt appear when eclipse plugin has been deployed? - eclipse

I have written an Eclipse plugin and I have added option for help in Eclipse "Help" menu. On click of that help the MessageBox appears.
This MessageBox appears when i run or debug by Eclipse application however when i deploy this plugin on other PC and click help the MessageBox doesnt appear.
This is my code:
public class MyHelp implements IWorkbenchWindowActionDelegate {
public void run(IAction arg0) {
try {
String message = "This is demo data";
// TODO Auto-generated method stub
MessageBox box = new MessageBox(new Shell(), SWT.OK);
box.setMessage(message);
box.setText("Help title");
box.open();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Can anyone help me out with this one ..?
For help I have added an ActionSet in my plugin as :
<extension
point="org.eclipse.ui.actionSets">
<actionSet
id="com.my.plugin.actionSet"
label="My ActionSet"
visible="true">
<menu
id="mymenu"
label="My Menu"
path="help/helpStart">
<groupMarker
name="start">
</groupMarker>
<separator
name="additions">
</separator>
</menu>
<action
class="com.myexample.MyHelp"
id="MyHelp"
label="Use Help"
icon="icons/plugin_help.png"
menubarPath="help/mymenu/start"
style="push">
</action>
</actionSet>
</extension>
Do I need to do anything else ?

If you are running eclipse >= 3.3 then you may drop it to plugins folder. Also, try to restart your eclipse with -clean option.
I'd suggest you to user dropins folder for manual installation. Please, refer to the documentation: http://wiki.eclipse.org/Equinox_p2_Getting_Started#Dropins
Upd1:
In order to run your code I had to add some unimplemented methods (I am using eclipse version 3.6):
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class MyHelp implements IWorkbenchWindowActionDelegate {
public void run(final IAction arg0) {
final String message = "This is demo data";
// TODO Auto-generated method stub
final MessageBox box = new MessageBox(new Shell(), SWT.OK);
box.setMessage(message);
box.setText("Help title");
box.open();
}
public void selectionChanged(final IAction action, final ISelection selection) {
// TODO Auto-generated method stub
}
public void dispose() {
// TODO Auto-generated method stub
}
public void init(final IWorkbenchWindow window) {
// TODO Auto-generated method stub
}
}
Also, check your plugin MANIFEST to have following line:
Bundle-SymbolicName: your_plugin_id;singleton:=true
I've just copied plugin from the workspace into the dropins folder of my eclipse instance and it was working out of the box.
Are you sure, that plugin manifest is in the jar file? Check out the Bin tab or build.properties to be sure, that everything is exported correctly.
Hope this helps

Related

Set tab title for an EditorPart in Eclipse

I currently have en Eclipse plugin that provides a multi-page editor, one page for a visual editor and one page for a source editor, similar to other editors, i.e:
This is the important part of my code:
public class DockerfileEditor extends FormEditor implements IResourceChangeListener {
....
#Override
protected void addPages() {
try {
SourceEditor sourceEditor = new SourceEditor(); // Extends from EditorPart
addPage(new DesignForm(this, "Design")); //$NON-NLS-1$
addPage(sourceEditor, sourceEditor.getEditorInput());
} catch (PartInitException e) {
e.printStackTrace();
}
}
}
In the addPages() method I'm adding my 2 pages, the first of them extends from FormPage so setting the title is really easy, but the second page extends from EditorPart (this will be my source editor), how can I set the title of this page?
addPage returns you the index of the page that was added so you can use:
int pageIndex = addPage(sourceEditor, sourceEditor.getEditorInput());
setPageText(pageIndex, "Source");

Eclipse JFace :: How to get rid of key binding conflicts while working in a multipage editor

I have an editor with multipage in which each page has copy paste delete actions and f3 navigation action. I create context and activate and deactivate the actions
Below is how the plugin.xml looks like :
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.sap.adt.wda.controller.ui.navigate"
contextId="com.sap.adt.wda.controller.ui.contextTabScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F3">
</key>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
description="%context_navigateToController_ymsg"
id="com.sap.adt.wda.controller.ui.contextTabScope"
name="%context_navigateToController_yins"
parentId="org.eclipse.ui.contexts.window">
</context>
</extension>
It is done through activation and deactivation of context. Below is the code snippet.
private void activateHandlers() {
IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
if (contextService != null) {
activation = contextService.activateContext(IControllerConstants.CONTEXT_TAB_ECLIPSE_CONTEXT_ID);
}
IEditorSite site = getEditor().getEditorSite();
IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
IHandlerActivation navigateHandlerActivation = service.activateHandler(NavigationHandler.COMMAND_ID, new NavigationHandler());
activatedHandlers = new ArrayList<IHandlerActivation>();
activatedHandlers.add(navigateHandlerActivation);
}
public void deactivateHandlers() {
IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
contextService.deactivateContext(activation);
IHandlerService service = (IHandlerService) getEditor().getEditorSite().getService(IHandlerService.class);
if (activatedHandlers != null) {
service.deactivateHandlers(activatedHandlers);
activatedHandlers = null;
}
}
These two methods are called respectively from the page change to activate the context once the page is active and deactivate when the page is not active.
The problem is that it still conflicts with another opened editor as when I switch between editors, pagechange is not even called!! Please tell me what is the best way to implement this.
Add focus listener on sourceViewer of editor
focusListener = new FocusListener() {
#Override
public void focusLost(FocusEvent e) {
deactivateHandlers();
}
#Override
public void focusGained(FocusEvent arg0) {
activateHandlers();
}
};
sourceViewer.getTextWidget().addFocusListener(focusListener);
On switch of every page the focusLost and focusGained will be called.
Override activateHandlers() and deactivateHandlers() to enable and disable respective handlers for each parts of editor

How to add an GUI component like a Button in a Editor?

I'm a beginner in RCP just started building RCP application today.I want to a GUI component like a Button ,comboBox,Checkbox in a Editor .I've managed to add a editor in Extensions and create a class for it.I have written the code to create a label in creatPartControl but it does not work..I get a black window.Should I add the editor in perspective like this
layout.addStandaloneView(Editor.id, true, IPageLayout.TOP,0.7f,
layout.getEditorArea());
layout.addStandaloneView(View.ID, true, IPageLayout.BOTTOM,0.4f,
layout.getEditorArea());
Please help me resolve this issue.If possible please give an eg on how to add a editor and create a label and a button in it.
Thank you for your help in advance
code in my Editor.java content in createPartControl()
parent.setLayout(new GridLayout());
Button b=new Button(parent,SWT.TOGGLE);
b.setText("Hello ");
Label label1 = new Label(parent, SWT.NONE);
label1.setText("First Name");
package com.hello;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
public class Editor extends EditorPart {
public static final String ID = "TestApplication.editor3";
public Editor() {
// TODO Auto-generated constructor stub
}
#Override
public void doSave(IProgressMonitor monitor) {
// TODO Auto-generated method stub
}
#Override
public void doSaveAs() {
// TODO Auto-generated method stub
}
#Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
// TODO Auto-generated method stub
}
#Override
public boolean isDirty() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isSaveAsAllowed() {
// TODO Auto-generated method stub
return false;
}
#Override
public void createPartControl(Composite parent) {
Label label = new Label(parent, SWT.NONE);
label.setText("sssssss");
}
#Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
You are not correctly initializing the editor and it causes problems when opening the editor. Fill up your init() method like below and see if this helps:
#Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
setInput(input);
}
It's been a few years since I worked on an Eclipse editor. Here's a screen capture of the editor so you can see I did more than add a Button.
I extended the Viewer class to create the GUI of the editor.
I extended the EditorPart class to create the functionality of the editor.
Because of the kind of editor I was building, I had to create my own version of Canvas and my own version of IDocument.

DragSourceListener never called while dragging and dropping file inside eclipse project explorer

I am working on eclipse plugin that will allow a java bean to be dragged onto jsp file then on the drop event some code generators will be called.
I'm attempting to use the extension point "org.eclipse.ui.dropActions" but drag and drop listeners never get called .Is there any way to attach drag and drop listener to IFile object.
Am I on the right track with the DropActionDelegate?
Code:
DragListener
class DragListener implements DragSourceListener {
#Override
public void dragFinished(DragSourceEvent event) {
System.out.println("Finish");
}
#Override
public void dragSetData(DragSourceEvent event) {
PluginTransferData p;
p = new PluginTransferData (
"dream_action", // must be id of registered drop action
"some_data".getBytes() // may be of arbitrary type
);
event.data = p;
}
#Override
public void dragStart(DragSourceEvent event) {
// TODO Auto-generated method stub
System.out.println("Start");
}
}
DropActionDelegate
class DropActionDelegate implements IDropActionDelegate {
#Override
public boolean run(Object source, Object target) {
String Data= (String) target;
return true;
}
}
Plugin.xml
<extension point="org.eclipse.ui.dropActions">
<action
id="dream_action"
class="newdreamfileplugin.wizards.DropActionDelegate">
</action>
</extension>
Thanks.
Solved it.Finally i created my own navigator using org.eclipse.ui.navigator.navigatorContent extension which have a property dropAssistant.

Is there a way to have Eclipse flash its taskbar icon once a time consuming task finishes?

I often minimize Eclipse to read or work on something else for a few minutes while I wait for it to do something (e.g., run a large JUnit test suite, synchronize a huge number of files with a repo, run a long Ant build, etc.). I have to check back every 30 seconds or so to see if it's finished yet. I would like Eclipse to alert me, preferably by blinking its taskbar icon, after it finishes a time consuming operation. Are there any settings or plugins that can make this happen?
I believe is you have Mylyn installed, this should be enabled by default for Windows 7. See here and here. Regarding the post-build actions, I do not know of any existing Eclipse plugins that do this. However, I have not exhaustively searched the marketplace. However, this could be accomplished with existing Eclipse APIs but it would require someone to author a new Eclipse plugin.
The Eclipse Platform jobs framework has an API called IJobManager. A developer could write a new Eclipse plugin that could use this API to listen for job changes and do the following:
Create an eclipse plugin, register a listener to IJobManager on startup.
Once any interesting job is completed, it could fire off some external task/script using normal java process execution API in the JDK
This all could be accomplished in one Java file, probably less than 500 lines long.
You could use this template to setup a basic Eclipse plugin project including build system and have it built and ready to install into your existing Eclipse.
Update I just found a maven archetype for building eclipse plugins with tycho here. It would be my recommendation for someone new to building an eclipse feature/updatesite.
You can create a new plugin project and create this kind of functionality for yourself. The
IJobchangeListener from the Eclipse Jobs API is probably very interesting for you.
The IJobChangeListener is an interface where you can receive notifications for the different type of job states.
I have created a class called JobListener which adds the IJobchangeListener to the JobManager. With the action SampleAction you can register or unregister the listener. that means, if the listener is registered and your application is minimized you will be notified with a MessageDialog (no blinking taskbar).
I found a link where someone made his swing application blink. This functionality should be included in the method public void done(final IJobChangeEvent event). I haven't done this in my test class.
You can also get additional information about the Job with
event.getJob();
Here you are able to check the Job name:
String jobName = event.getJob().getName();
The name of the Job is human readable, for example "Collecting garbage", "Update for Decoration Completion", "Building workspace", etc.
The JobListener class.
/**
* A job listener which may be added to a job manager
*/
public class JobListener {
private MyJobListener listener = null;
private IWorkbenchWindow window = null;
private boolean active = false;
public JobListener(IWorkbenchWindow window) {
this.window = window;
}
/**
* register the job listener
*/
public void register() {
listener = new MyJobListener(window);
IJobManager jobMan = Job.getJobManager();
jobMan.addJobChangeListener(listener);
active = true;
}
/**
* unregister the job listener
*/
public void unregister() {
IJobManager jobMan = Job.getJobManager();
jobMan.removeJobChangeListener(listener);
active = false;
}
public boolean isActive() {
return active;
}
class MyJobListener implements IJobChangeListener {
private IWorkbenchWindow window;
public MyJobListener(IWorkbenchWindow window) {
this.window = window;
}
#Override
public void sleeping(IJobChangeEvent event) {
}
#Override
public void scheduled(IJobChangeEvent event) {
}
#Override
public void running(IJobChangeEvent event) {
}
#Override
public void done(final IJobChangeEvent event) {
window.getShell().getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
if(window.getShell().getMinimized()) {
MessageDialog.openInformation(
window.getShell(),
"Test",
"Job " + event.getJob().getName() + " done.");
}
}
});
}
#Override
public void awake(IJobChangeEvent event) {
}
#Override
public void aboutToRun(IJobChangeEvent event) {
System.out.println("About to run: " + event.getJob().getName());
}
}
}
I called this class from a class called SampleAction.java
public class SampleAction implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
private JobListener listener;
/**
* The constructor.
*/
public SampleAction() {
}
public void run(IAction action) {
if(listener.isActive()) {
listener.unregister();
MessageDialog.openInformation(
window.getShell(),
"Lrt",
"Unregistered");
}
else {
listener.register();
MessageDialog.openInformation(
window.getShell(),
"Lrt",
"Registered");
}
}
public void selectionChanged(IAction action, ISelection selection) {
}
public void dispose() {
}
public void init(IWorkbenchWindow window) {
this.window = window;
this.listener = new JobListener(window);
}
You can get started with eclipse plugin development by creating a new plugin project:
File > New > Project > Plugin Project
I used the Hello World plugin project template to test the code above.