How do I make the "user operation is waiting" dialog invisible in Eclipse RCP? - eclipse-plugin

I'm creating a web development framework with Eclipse RCP.
The wizard is creating a feature that creates a project when you press Finish.
I want to show Process Monitor at the bottom of the wizard
I wrote the code as below.
public abstract class CreateProjectWizard extends Wizard {
public CreateProjectWizard () {
...
setNeedsProgressMonitor(true);
}
...
#Override
public boolean performFinish() {
IRunnableWithProgress runnable= new IRunnableWithProgress() {
#Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
...
IStatus status = createProject(input, monitor);
...
}
};
try {
getContainer().run(true, true, runnable);
}
...
return true;
}
}
How do I make the "user operation is waiting" dialog invisible?
I will let you know if you need additional information.

It looks like you should be able to call Dialog.setBlockedHandler with something that implements IDialogBlockedHandler to change this dialog (both in org.eclipse.jface.dialogs).
The blocked handler does not have to display a dialog, the default JFace handler is just:
new IDialogBlockedHandler() {
#Override
public void clearBlocked() {
// No default behavior
}
#Override
public void showBlocked(IProgressMonitor blocking,
IStatus blockingStatus, String blockedName) {
// No default behavior
}
#Override
public void showBlocked(Shell parentShell, IProgressMonitor blocking,
IStatus blockingStatus, String blockedName) {
// No default behavior
}
};
Eclipse normally replaces this with org.eclipse.ui.internal.dialogs.WorkbenchDialogBlockedHandler which shows the dialog you see (BlockedJobsDialog).
Note that this will not stop the operation waiting for the blocking jobs to finish it will just stop the dialog appearing.

Related

Eclipse Plugin: How can I tell the plugin to open a new Editor every time instead of switching the focus to an existing Editor?

In my Plugin there is an action to open an Editor (extends EditorPart). When I try to open it a second time, its init method isn't called. Instead the focus is shifted to the editor that is already open.
The Editor is associated with a filetype. Here is the excerpt from the plugin.xml:
<extension point="org.eclipse.ui.editors">
<editor
class="de.blub.tool.ide.editors.GRASPEditor"
default="true"
extensions="grasp"
filenames="*.grasp"
icon="icons/newGraspFile.png"
id="de.blub.tool.ide.editors.GRASPEditor"
name="GRASP File Editor">
</editor>
</extension>
I have an Action to open a new Editor. When I try to click that Action twice it reuses the first Editor. I also tried to use an EditorMatcher that implements IEditorMatchingStrategy and always returns false in its matches() method. Even that doesn't change the behavior.
This seems to be a desired/default behavior in eclipse. How can I change that so that the user can initialize a new Editor each time?
Eclipse looks for the equals method of the IEditorInput instance. The Editor somewhere in its code (in my case in the doSave method) uses a setInput method like this:
#Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
// Initialize the editor input
this.input = new MyInputClass(resource);
...
}
#Override
public void doSave(IProgressMonitor monitor) {
...
setInput(input);
}
MyInputClass is the class that extends IEditorInput. The logic for eclipse to reuse an Editor or create a new one is in its equals method. The following example checks the path of an IResource field:
public class MyInputClass implements IEditorInput {
private IResource resource;
public MyInputClass(IResource resource) {
this.resource = resource;
}
public IResource getResource() {
return resource;
}
public void setResource(IResource resource) {
this.resource = resource;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj instanceof MyEditorClass) {
MyEditorClass other = (MyEditorClass) obj;
if (getResource().getFullPath().equals(other.getResource().getFullPath())) {
return true;
}
}
return false;
}
}
Of course one can define another logic inside the equals method. Make sure to not create a chaos, which is very well possible, as greg-449 pointed out in a comment.

Creating a custom run configuration using IntelliJ SDK and adding Build task in Before launch section

I'm following the tutorial in Run Configuration section of IntelliJ IDEA SDK.
Following the tutorial, I will get a new configuration panel with an empty "Before launch" section. That section is added by default.
I would like to specify some targets by default, i.e. at least the Build target as done in several plugins (see next picture)
I'm trying to understand how, but I cannot find any example nor documentation on this.
How can I add default build task?
Your run configuration (DemoRunConfiguration in the example) should implement RunProfileWithCompileBeforeLaunchOption. This interface doesn't provide any methods to implement, so this is a kind of mark. build task will be added automatically, no additional steps are required.
How can I add my own task to before launch section?
Your plugin.xml should contain a line with stepsBeforeRunProvider
<stepsBeforeRunProvider implementation="com.MyBeforeRunProvider" id="myBeforeRun"/>
For that you should create "before run provider" with "before run task".
public class BeforeRunProvider extends BeforeRunTaskProvider<MyBeforeRunTask> {
#Override
public Key<MyBeforeRunTask> getId() {
return Key.create("ThisIsId");
}
#Override
public String getName() {
return "Nice name";
}
#Override
public String getDescription(MyBeforeRunTask task) {
return "Description";
}
#Nullable
#Override
public Icon getIcon() {
return AllIcons.Actions.Compile;
}
#Nullable
#Override
public MyBeforeRunTask createTask(#NotNull RunConfiguration runConfiguration) {
return new MyBeforeRunTask(getId());
}
#Override
public boolean executeTask(#NotNull DataContext dataContext, #NotNull RunConfiguration runConfiguration, #NotNull ExecutionEnvironment executionEnvironment, #NotNull MyBeforeRunTask myBeforeRunTask) {
return true;
}
}
And the task:
public class MyBeforeRunTask extends BeforeRunTask<MyBeforeRunTask> {
protected MyBeforeRunTask(#NotNull Key<MyBeforeRunTask> providerId) {
super(providerId);
setEnabled(true);
}
}

Realtime checking the progress monitor using Job.getJobManager.IsIdle()

I am trying to continuously check if the progress monitor has an operation that is running in the background.
For this, I used Job.getJobManager.IsIdle().
I have tried the following:
Put it inside a Job.
WorkspaceJob job = new WorkspaceJob("Hello")
{
#Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException
{
while(!Job.getJobManager().isIdle())
{
System.out.println(!Job.getJobManager().isIdle());
}
return Status.OK_STATUS;
}
};
job.setPriority(Job.SHORT);
job.schedule();
But this does not work as Job.getJobManager.isIdle will never return false because Job 'Hello' is running.
Put it inside an asynchronous thread.
new Thread(new Runnable()
{
#Override
public void run()
{
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
while(!Job.getJobManager().isIdle())
{
System.out.println("hi");
}
}
});
}
}).start();
But this does not work either as this will freeze the main Eclipse GUI preventing other processes (if there are any existing) to finish.
If anyone has suggestions or any input on how it should be done, it would be great!
You can use a job change listener IJobChangeListener to listen for all changes to job states. You can than test for idle in appropriate places in the listener. Do not try and loop calling isIdle.
You can use the JobChangeAdapter class which provides default implementations of the IJobChangeListener methods so that you only have to override the events you are interested in, probably just the done method:
Job.getJobManager().addJobChangeListener(new JobChangeAdapter()
{
#Override
public void done(IJobChangeEvent event)
{
if (Job.getJobManager().isIdle() {
// Manager is idle
}
}
});

Eclipse Plugin - execute when user changes window in perspective

I would like to ask how would you automatically execute a plugin when a user switches windows in the perspective.
Can this be done maybe with startup handler and IWorkbench?
You can use IPartListener to listen to changes in which part is active.
You can set this up in using IStartup but you need to do this using something like this:
public class StartUp implements IStartup
{
#Override
public void earlyStartup()
{
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
window.getPartService().addPartListener(your part listener);
}
}
});
}
}
This is using Display.asyncExec to delay setting up the part listener until after the startup has completed as the workbench window will not be available when earlyStartup runs.

Save option in RCP Product

Iam developing a RCP application which consists of views and editors. I can change the values and edit the values of some parameters in editor. When a value has been changed, i need to make the editor dirty as well as would also like to enable the save button. Till now, i have not implemented my save button. Could anyone guide me how to make the save button enabled as well as how can i make an editor dirty when some modifications happen in editor.
Thanks in advance. Any help will be greatly appreciated.
Regards,
Girish
Here is an overview of the Form editor logic, hop it will help you.
public class TestEditor extends FormEditor {
#Override
protected void addPages() {
// this method is called when the editor is being created
// to add the necessary pages
// page classes should be like following
// class TestEditorPage extends FormPage
try {
TestEditorPage pageTest = new TestEditorPage(this);
addPage(pageTest);
} catch (PartInitException e) {
}
}
#Override
public void doSave(IProgressMonitor monitor) {
// this method will be called on save action
// (or Ctrl + s shortcut)
}
#Override
public void doSaveAs() {
// this method will be called on save-as
//call (or Ctrl + Shift + s shortcut)
}
#Override
public boolean isSaveAsAllowed() {
// put here the call to the logic that
// check if the save is allowed
return true;
}
#Override
public boolean isDirty() {
// Here the call for the logic that
// defines if the editor is dirty or not
return true;
}
}