remove p2 install/update preference in menu tools - eclipse-rcp

I must remove the install/update preference in the menu Tools' preferences. How can I do?
Thank to everybody.

If we are talking about an RCP app, open your ApplicationWorkbenchAdvisor class and use something like this:
PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
for (IPreferenceNode node : pm.getRootSubNodes()) {
if (node.getId().equals("org.eclipse.equinox.internal.p2.ui.sdk.ProvisioningPreferencePage")) {
pm.remove(node);
}
}

public void postStartup() {
PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager( );
pm.remove("org.eclipse.equinox.internal.p2.ui.sdk.ProvisioningPreferencePage");
pm.remove("org.eclipse.update.internal.ui.preferences.MainPreferencePage");
}

Related

How to include a preference page into the preference dialog

I know the way to add preference pages into the common preference dialog for an e3 RCP application. I have an e4 RCP application and I read that the preference dialog works different.
I found the way to open the common preference dialog, but I didn't find a way to include a customized preference page into the dialog.
public class PreferenceHandler {
#CanExecute
public boolean canExecute()
{
return true;
}
#Execute
public void execute(#Named(IServiceConstants.ACTIVE_SHELL) Shell shell, E4PreferenceRegistry prefReg,
#Optional #Named("preferencePageId") String pageId) {
PreferenceManager pm = prefReg.getPreferenceManager();
// Can display the standard dialog.
PreferenceDialog dialog = new PreferenceDialog(shell, pm);
if (pageId != null)
{
dialog.setSelectedNode(pageId);
}
dialog.create();
dialog.getTreeViewer().setComparator(new ViewerComparator());
dialog.getTreeViewer().expandAll();
dialog.open();
}
}
Most of the preference page code is part of e3 and isn't available in e4. Only the very basic JFace code is available.
So you will have to add each preference page you want directly to the PreferenceManager. Something like:
PreferenceManager pm = ... preference manager
IPreferencePage page = ... create your preference page
page.setTitle("title of the page");
IPreferenceNode node = new PreferenceNode("id of the page", page);
pm.addToRoot(node);

In ecplipse RCP application automatically get Run option in menubar Want to remove it

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");
}
}
}

Eclipse RCP: Can I remove Orphaned Perspectives from the Perspective Bar?

I'm developing an RCP that has two product versions, a core app and one with some extensions. If a user opens the core app after having opened the extended app in the same workspace, eclipse detects a perspective used only in the extended app and makes a local copy of it, so it shows up in the perspective toolbar as an orphaned extension.
I created an activity to hide the extended app perspective when running the core app. That hides it from the perspective menu and the perspective shortcut menu, but it doesn't remove it from the perspective toolbar.I also tried detecting orphaned perspectives from the active page of the active workbench window (by looking for angle brackets in the label) and removing them with PlatformUI.getWorkbench().getPerspectiveRegistry().deletePerspective(perspective), but this doesn't affect the perspective toolbar either. The perspective I'm removing is not present in the core app.
Is there a way I can access the perspective toolbar programmatically so I can remove any orphaned perspectives? Or any other approach tha would work?
I thought a good solution would be creating a custom perspective switcher, but that path was blocked by an eclipse bug. There is a suggested workaround, but it did not work for me. I created a custom perspective switcher toolbar, but I could find no way to make it update when perspectives are opened or activated. My attempts are documented here.
I removed the orphan perspectives in a workspace shutdown hook, but for some reason an NPE is thrown by the E4 workbench (LazyStackRenderer line 238) when I select a perspective in the switcher that was opened but not selected when I launched the app.
I got it to work as desired by closing all open perspectives on shutdown, after storing their IDs in a preference value, and then opening them again when the app is launched in the WorkbenchWindowAdvisor. It's a bit of a hack, but it's the only way I could find to avoid the E4 workbench NPE, which also prevents setting the perspective from the toolbar until it's closed and re-opened from the Window menu.
Here's my code.
...
IWorkbench workbench = ...
static final String PERPSECTIVE_ID_1 = ...
static fnal String PERSPECTIVE_ID_2 = ...
static final String PREFERENCE_KEY = ...
workbench.addWorkbenchListener( new IWorkbenchListener() {
public boolean preShutdown( IWorkbench workbench, boolean forced ) {
IPerspectiveDescriptor[] openPerspectives = page.getOpenPerspectives();
page.closeAllPerspectives(false, false);
StringBuilder sb = new StringBuilder();
String delim = "";
for (IPerspectiveDescriptor persp : openPerspectives) {
if (!persp.getId().equals(PERSPECTIVE_ID_1) && !persp.getId().equals(PERSPECTIVE_ID_2) {
sb.append(delim + persp.getId());
delim = ";";
}
}
getPreferenceStore().setValue(PREF_KEY, sb.toString());
return true;
}
public void postShutdown( IWorkbench workbench ) {
}
});
class MyWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
static final String PRODUCT_ID_1 = ...
static final String PRODUCT_ID_2 = ...
static final String PREFERENCE_KEY = ...
...
#Override
public void postWindowOpen() {
IWorkbenchPage page = getWindowConfigurer().getWindow().getActivePage();
String savedOpenPerspectiveStr = getPreferenceStore().getString(PREFERENCE_KEY);
if (!"".equals(savedOpenPerspectiveStr)) {
List<IPerspectiveDescriptor> openPerspectives = new ArrayList<IPerspectiveDescriptor>();
String[] perspectiveIds = savedOpenPerspectiveStr.split(";");
if (perspectiveIds.length == 0) {
openPerspectives.add(PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(savedOpenPerspectiveStr));
} else {
for (String id : perspectiveIds) {
openPerspectives.add(PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id));
}
}
//successively setting perspectives causes them to appear in the perspective switcher toolbar
for (IPerspectiveDescriptor persp : openPerspectives) {
page.setPerspective(persp);
}
}
//now we set the appropriate perspective
if (Platform.getProduct().getId().equals(PRODUCT_ID_1)) {
page.setPerspective(PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(PERSPECTIVE_ID_1));
} else if (Platform.getProduct().getId().equals(PRODUCT_ID_2)) {
page.setPerspective(PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(PERSPECTIVE_ID_2));
}
}
...
}

How do i restart my eclipse

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();
}
}
});
}

Enumerating all my Eclipse editors?

I have built a simple Eclipse plugin where a user may use a TableViewer of database resources to open an editor on any of those resources.
Users may therefore have zero upwards instances of the editor running.
Is there an API available to get a list of those editor instances?
You can get references to all open editors with:
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getEditorReferences();
And then check these to select the ones that reference instances of your editor type.
According to the javadoc for the API a workbench can have several windows, and a window can have several pages, and they do not share editors.
So, in order to get all and every open editor, you should do something along these lines (error checking etc excluded):
List<IEditorReference> editors = new ArrayList<IEditorReference>();
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IEditorReference editor : page.getEditorReferences()) {
editors.add(editor);
}
}
}
Be aware the such an enumeration will not respect the tab order
Here is an example of an enumeration of editors:
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IWorkbenchPage page = window.getActivePage();
IEditorPart actEditor = page.getActiveEditor();
IEditorReference[] editors = page.getEditorReferences();
for (int i=0; i<editors.length-1; i++) {
if (editors[i].getEditor(true) == actEditor) {
page.activate(editors[i+1].getEditor(true));
return null;
}
}