what is method to call the eclipse Save/SaveAs option programatically in plugin [duplicate] - eclipse

I am developing a plug-in.
On clicking a button, I'd like to call the save method of Eclipse or call the save button on Eclipse toolbar.
What is the way to do it?

org.eclipse.ui.PlatformUI.getWorkbench().saveAll(..)
should do the trick.
If you want to save the active editor, please try
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.getActiveEditor();
page.saveEditor(editor, true /* confirm */);
Note that the elements in the navigation path may be null.

I use this to save dirty editors for one or more projects:
//Save all changes
Display.getDefault().syncExec(new Runnable() { // save all editors needs to be called by the ui thread!
#Override
public void run() {
IDE.saveAllEditors(new IResource[]{prj}, true);
}
});
where prj is an IProject object.
hope this helps
bye

I used -
IDEWorkbenchPlugin.getDefault().getWorkbench().saveAllEditors(true);

Related

how to dianmically add dialog to webpage in wicket?

I have write my own dialog and on my Index page have a AjaxLink
when AjaxLink is clicked. I will behave to open my dialog instance.
this is my code
add(new AjaxLink("open.working.date.dialog") {
#Override
public void onClick(AjaxRequestTarget target) {
WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
Index.this.add(dialog);
dialog.open(target);
}
});
of course, on my web page html markup I don't have reference component id working.date.dialog and it will throw exception.
but when I replace Index.this.add(dialog); by this.add(dialog); or by target.add(dialog); the dialog won't work.
There any other way to add dynamically dialog to page?
In jquery I can do that easily by just append dialog html to body then open it by jquery.
thanks for your all helpful!
One option is to add the dialog in the constructor of the page and hide it initially. Then later when clicking the link just mark it as visible and add it to the AjaxRequestTarget.
Another option is to add a dummy/empty WebMarkupContainer with the same component id and later replace it with the dialog in #onClick().
You are going against the wicket way of doing things here, which will cause you much pain. :-) First of all WorkingDateDialog needs to extend ModalWindow. Assuming it does, here are my suggestions.
Right above your ajax link add this code:
final WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
add(dialog);
Then your ajax link becomes:
add(new AjaxLink("open.working.date.dialog") {
#Override
public void onClick(AjaxRequestTarget target) {
dialog.show(target);
}
});
So you always add your ModalWindow instance to your page hierarchy. It' just not visible until someone clicks the link.
I hope this helps you. Please let me know if you have any questions.

Eclipse RCP 4.x show view

I'm working for a short time on the libraries of eclipse 4.x someone could tell me how can I open a view through from the context menu? Thank you in advance.
To show a part anywhere you should define a command in the application model and a handler for the command. To show a part in the handler use:
#Execute
public void execute(EPartService partService)
{
MPart mpart = partService.showPart(part id, PartState.ACTIVATE);
}
In the application Part definition for your part add a Popup Menu to the Menus section. In the popup menu define a HandledMenuItem for your command.
To register the popup menu as the context menu for a control (tree, table etc) use:
#Inject
private EMenuService;
...
menuService.registerContextMenu(control, menu id);

How to remove or set help content to the Help menu available in WizardDialog in eclipse plugin

I am calling WizardDialog dialog = new WizardDialog and a new window is opening with a help icon in the bottom button tray in extreme left corner. I don't need that button.
How to remove that or is there any way to add help content to it.
According to bug 330206:
To hide the "?" you need to call setHelpAvailable(false) on your WizardDialog.
If you don't control/create the dialog, you can add the following method to
your wizard:
public void setContainer(IWizardContainer wizardContainer) {
super.setContainer(wizardContainer);
if (getContainer() instanceof TrayDialog)
((TrayDialog)getContainer()).setHelpAvailable(false);
}
To add Help, you can see the general idea in this thread, but take into account bug 3827:
if you are opening the wizard in a WizardDialog you create, you have to set help on the dialog's shell: ex.
dialog.create();
WorkbenchHelp.setHelp(dialog.getShell(), new Object[]{IHelpContextIds.NEW_WIZARD});
dialog.open();

Refreshing the workbench

HI,
I am facing some problem.. I want to hide the menu when eclipse workbench starts.
But the problem is menu is not hiding when the eclipse workbench starts. It is hiding only
when some refresh is happened. for example: when I change the default perspective to some other perspective, I am getting the desired out put. That means menu is hiding.
But when the eclipse workbench is loaded it is not hiding the menu. Below is my code.
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item:items){
System.out.println("item.getId()::: "+item.getId());
menuManager.remove("org.eclipse.ui.run");
menuManager.remove("help");
menuManager.remove("project");
}
}
}`
}
};
Given that you are looking to hide some features, I don't think that this is the best approach. (Not I am using the term feature here in the colloquial way, not as an Eclipse feature.
I would recommend one of two avenues:
Perspectives: See the extension point org.eclipse.ui.perspectives. This allows you to create a new perspective like the debug perspective or the Java perspective. Using a perspective, you can select exactly what menu items and views are shown and which ones are hidden.
Capabilities (aka activites): See the extension point org.eclipse.ui.activities. This allows you to have some fairly fine-grained control over what features are available in the workspace. See more info here: http://wiki.eclipse.org/Galileo_Capabilities
Put Your code in org.eclipse.ui.startup extention point. Make a Startup class after implementing the interface IStartup. For Details follow this link:-
Eclipse plugin : disable/enable dynamically an action from main menubar

How do I stop an Eclipse Editor from closing in an RCP

I am working on an Eclipse based RCP. We have a need to prevent one of the opened editors from being closed by the user.
The desired behavior is:
the user clicks the X in the editor window or "CTRL+W"
a dialog pops up saying: "If you close this editor, your activity will stop. Do you want to?"
if they click yes, it closes, if no, it stays open.
Oh yeah, and is this even possible?
Thanks,
gk
You could use a org.eclipse.ui.ISaveablePart2, more specifically the method promptToSaveOnClose().
However, as said in this thread,
it will only be shown if the editor is dirty at the time it is closed.
See an example in this SaveableHelper.java source file.
See also the article Prevent that a RCP Editor is closed, which explains how this method works:
You can also cancel the saving in
#Override
public void doSave(IProgressMonitor monitor) {
by calling
monitor.setCanceled(true);
In the EditorPart implementation
Not directly related but I was looking for a way to prevent an Editor to be closed and found this little hack, hope it could help.
page.addPartListener(new IPartListener2() {
// [...]
#Override
public void partClosed(IWorkbenchPartReference partRef) {
try {
page.openEditor(input, id);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});