I am trying to write a script for my eclipse updatesite. I am updating all my plugins to plugins folder and feature to features folder to their latest versions available using a pom.xml file.
Now my requirement is, i want to add a eclipse restart command to prompt for the user input with "Restart Now" "Restart later" buttons like we see in regular eclipse update site work flow.
Can anyone provide me some inputs for this?
Try with this code
Display display = Display.getDefault();
if (display != null) {
display.asyncExec(new Runnable() {
public void run() {
MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
"Dialog title"
null, "Restart eclipse?"
MessageDialog.QUESTION, new String[] { "OK","Restart Later" }
0);
if (dialog.open() == 0) {
PlatformUI.getWorkbench().restart();
}
}
});
}
Related
enter image description hereIn my Eclipse RCP application i am getting Run option automatically in menu bar. Without writing any code.So, i want to remove this.
Also getting search menu by default. which is ok for this application. But, my manually created menu item like(File, editor) , these items and search menu item distance not same manner.please help me out this situation to overcome on distance on manu item in eclipse RCP.
I suggest use plugin spy feature. Alt+shift+F1, Alt+shift+F2.
You can use in your development environment first, and you can use plugin spy on your rcp. just add org.eclipse.pde.runtime plugin to your rcp.
And you can figure out which plugin contributes menu item on your rcp, and if you think that plugin is not necessary, you can remove that plugin from your rcp.
For removing all defaults options in menu, You need to add this below code in ApplicationWorkbenchWindowAdvisor.java class.
#Override
public void postWindowOpen() {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IContributionItem[] items = ((WorkbenchWindow)workbenchWindow).getMenuBarManager().getItems();
for (IContributionItem item : items) {
item.setVisible(false);
}
}
The compiler will remind that it is not recommended to use WorkbenchWindow to access the UI, which conflicts with the library org.eclipse.ui.workbench in the Target.
#Override
public void postWindowCreate() {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (int i = 0; i < windows.length; i++) {
IWorkbenchPage page = windows[i].getActivePage();
if (page != null) {
IMenuManager menuMgr = getWindowConfigurer().getActionBarConfigurer().getMenuManager();
IContributionItem[] items = menuMgr.getItems();
for (IContributionItem item: items) {
if (item.getId().equals("org.eclipse.ui.run")) {
item.setVisible(false);
} else if (item.getId().equals("org.eclipse.search.menu")) {
item.setVisible(false);
}
System.out.println(item);
}
page.hideActionSet("org.eclipse.search.searchActionSet");
}
}
}
I changed it to get the MenuManager from getWindowConfigurer().getActionBarConfigurer().getMenuManager();
This can solve it.
Just paste this below code in ApplicationWorkbenchWindowAdvisor.java class.
public void postWindowOpen() {
// remove unwanted UI contributions that eclipse makes by default
IWorkbenchWindow[] windows = PlatformUI.getWorkbench ().getWorkbenchWindows();
for (int i = 0; i < windows.length; ++i) {
IWorkbenchPage page = windows[i].getActivePage();
if (page != null) {
WorkbenchWindow workbenchWin = (WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MenuManager menuManager = workbenchWin.getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item : items) {
if(item.getId().equals("org.eclipse.ui.run")){
item.setVisible(false);
}
}
// hide 'Search' commands
page.hideActionSet("org.eclipse.search.searchActionSet");
}
}
}
How I can open specific help topic in eclipse help window programatically running on Linux(Ubuntu 14.04)?
Ex: I want to open "Tasks view" help as shown in below pic pro-grammatically.
I tried with:
PlatformUI.getWorkbench().getHelpSystem() .displayHelpResource("/org.eclipse.platform.doc.user/concepts/ctskview.htm");
But the help topic is opening in external browser(firefox) NOT in eclipse help widow.
How I can open this topic in eclipse help widow(Window which opens when clicked Help > Help contents menu in eclipse workbench).
According to your print screen you are using Linux. The internal Window only works for Windows.
Have a look at the code in DefaultHelpUI (On non Windows platforms, use external when modal window is displayed):
private boolean useExternalBrowser(String url) {
// On non Windows platforms, use external when modal window is displayed
if (!Constants.OS_WIN32.equalsIgnoreCase(Platform.getOS())) {
Display display = Display.getCurrent();
if (display != null) {
if (insideModalParent(display))
return true;
}
}
// Use external when no help frames are to be displayed, otherwise no
// navigation buttons.
if (url != null) {
if (url.indexOf("?noframes=true") > 0 //$NON-NLS-1$
|| url.indexOf("&noframes=true") > 0) { //$NON-NLS-1$
return true;
}
}
return false;
}
On Eclipse Luna, I select a server and click the Start button on Servers view, then the server (for example Tomcat8) will get started. If something is wrong during the start-up process, a dialog will be populated to display the error messages (for example time-out). The dialog is modeless in this test case.
Now I need to start the server programmatically from a plugin. In case that errors occur, how could I programmatically detect that a dialog has been opened and how to close it?
You could use the Display.addFilter method to listen for all SWT.Activate events which will tell you about all Shells (and other things) being activated. You can then detect the shells you want to close.
Something like:
Display.getDefault().addFilter(SWT.Activate, new Listener()
{
#Override
public void handleEvent(final Event event)
{
// Is this a Shell being activated?
if (event.widget instanceof Shell)
{
final Shell shell = (Shell)event.widget;
// Look at the shell title to see if it is the one we want
if ("About".equals(shell.getText()))
{
// Close the shell after it has finished initializing
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
shell.close();
}
});
}
}
}
});
which closes a dialog called 'About'.
In more recent versions of Java the above can be simplified to:
Display.getDefault().addFilter(SWT.Activate, event ->
{
// Is this a Shell being activated?
if (event.widget instanceof Shell shell)
{
// Look at the shell title to see if it is the one we want
if ("About".equals(shell.getText()))
{
// Close the shell after it has finished initializing
Display.getDefault().asyncExec(shell::close);
}
}
});
This uses Java 8 lambdas and method references and Java 16 instanceof type patterns.
i'm working on an Eclipse RCP4 project. I have different perspectives showing a set of Parts to choose informations from. After selecting what i want to see, a new Part opens and displays the objet i want to edit / view attibutes of.
I can open many parts of the same type. If i close the application, the eclipse framwork persists the position of all opened Parts. If i restart the application all previously opened Parts are open but without informations.
-How to prevent Eclipseframwork from persisting the state of Parts?
-How to close Parts on exit?
I'm searching for a way to add an "removeOnExit" tag to a Part and than close such a marked Part on exit.
Thanks in advance :)
With this you can close MParts with a specific Tag.
It seems you have to switch to the Perspective the Part is on, else it's not removed from the context wich will cause nullpointer exceptions.
#Inject
#Optional
public void doEvent(#EventTopic(EventConstants.EventTopics.CLOSE_PARTS_WITH_TAGS) String tagToClose, MApplication app,
EModelService eModelService, EPartService ePartService) {
MUIElement activePart = ePartService.getActivePart();
EPartService activePeServcie = null;
MPerspective activePerspective = null;
if (activePart instanceof MPart) {
activePeServcie = ((MPart) activePart).getContext().get(EPartService.class);
activePerspective = eModelService.getPerspectiveFor(activePart);
}
List<String> tags = new ArrayList<String>();
tags.add(tagToClose);
List<MPart> elementsWithTags = eModelService.findElements(app, null, MPart.class, tags);
for (MPart part : elementsWithTags) {
try {
logger.info("Closing part " + part.toString());
EPartService peService = part.getContext().get(EPartService.class);
peService.switchPerspective(eModelService.getPerspectiveFor(part));
peService.hidePart(part);
} catch (Exception e) {
logger.error(e);
}
}
if (activePart instanceof MPart && activePeServcie != null && activePerspective != null) {
activePeServcie.switchPerspective(activePerspective);
}
}
We too tried to migrate from Eclipse 3 to Eclipse 4.We used the comp layer and had a lot of problems with the migration. I had a similar problem with persistent store of the eclipse workbench. So parts and views had the same position as before restart.
The persistence paradigma in Eclipse 4 has changed. Please take a look here:
As far as I remember the call of configurer.setSaveAndRestore(false) does not work in Eclipse 4 correctly.
I have created a Dialog with two buttons Yes, No, and then I have add action listener to them, my problem is that I want no button to hide the Dialog that I have created
the code is looks like:
dialog = new Dialog(title);
dialog.setDialogType(Dialog.TYPE_CONFIRMATION);
ta = new TextArea(text);
ta.getStyle().setBorder(Border.createEmpty());
ta.setEditable(false);
yesCommand = new Button("YES");
noCommand = new Button("NO");
yesCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
LGBMainMidlet.getLGBMidlet().notifyDestroyed();
}
});
noCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Logger.Log("Bye Bye");
dialog = null;
System.gc();
}
});
dialog.addComponent(ta);
dialog.addComponent(yesCommand);
dialog.addComponent(noCommand);
dialog.show();
the code is not working for me, can anyone told me what is the problem?
B.N. I have used dialog.dispose(), but it exit the whole application
It is better to use
dialog.setTimeout(1000); the number show the time limit the dialog box wait in milliseconds. So by doing this you can exit the dialog form automatically.
Dialog.dispose() does not exit the whole application, it just closes the dialog.
If you have nothing in your application you might see nothing if you dispose the dialog.