Programmatically open a specific tab of the Eclipse CDT project property page - eclipse

I would like to open a specific tab of the Eclipse CDT project property page from code. For example the screenshot below shows the property page open on the Build Steps tab.
The following code opens the property page succesfully, but always the last accessed tab.
private void openProperties(IProject project) {
String ID = "org.eclipse.cdt.managedbuilder.ui.properties.Page_BuildSettings";
org.eclipse.swt.widgets.Shell shell = org.eclipse.swt.widgets.Display.getCurrent().getActiveShell();
org.eclipse.ui.dialogs.PreferencesUtil.createPropertyDialogOn(
shell, project,
ID, null, null, 0)
.open();
}
The thing I don't quite understand is the Settings page is declared using extension point="org.eclipse.ui.propertyPages" and has an ID. But the tabs are added using extension point="org.eclipse.cdt.ui.cPropertyTab" which does not include an ID. So how are the tabs addressed without an ID?

This is only a partial solution, but hopefully it helps:
Save the return value of createPropertyDialogOn(). It's a PreferenceDialog.
Call getSelectedPage() on it to get the IPreferencePage representing the page.
Most CDT preference pages, including the Build Settings page, extend from org.eclipse.cdt.ui.newui.AbstractPage. AbstractPage uses an SWT TabFolder widget to store the tabs.
Here's the fuzzy part: get a hold of the TabFolder widget for the page. Unfortunately, it's not exposed via any public API, so I think your options are:
Use reflection. The TabFolder is stored as a protected field of the AbstractPage named folder.
Search the SWT widget hierarchy rooted at page.getControl(), where page is the AbstractPage, for a TabFolder.
Once you have the tab control, you can use getItemCount() and getItem(index) on it to enumerate its items, which will be of type TabItem.
On each TabItem, call getData() to retrieve the associated ICPropertyTab.
Examine the ICPropertyTab object to see if it's the one you want to activate. In your case, that might be a check like tab instanceof org.eclipse.cdt.managedbuilder.ui.properties.BuildStepsTab.
Once you've found the right tab, activate it via folder.setSelection(item).

Related

Filtering contents in Eclipse Common Navigator Framework view

I am developing a 3.x based Eclipse RCP application. In the part of application, I am implementing Common-navigator plugin of Eclipse itself, in order to display resources in the workspace. I'have created the navigator view shown below:
But I would like display only one tree child element. More specifically, I only want clause folder and its elements to be shown.
What is the accurate way to do it?
Add dependecy of org.eclipse.ui.navigator if not exists in plugin.xml.
Add extension point org.eclipse.ui.navigator.navigatorContent in extension tab.
Create CommonFilter under that and provide your values to the properties on the right.
Create a class which extends 'org.eclipse.jface.viewers.ViewerFilter' and implement you logic in overridden public boolean select(Viewer viewer, Object parentElement, Object element) (Note : return true would retain the resource in Navigator otherwise it will be hidden).
Configure this extended class in extension for class property in CommonFilter.
And you are good to go for testing.
BTW, this way is adding common filter to across all the Navigator. If you need to configure for particular navigator then you need to get its view and then get viewer out of it and attach your filter to viewer. To achieve this you may need a trigger point e.g., a menu/button/startup extension!

Customizing Element Properties Menu in Enterprise Architect

I have created a new stereotype based on "Requirement" and has exported it as profile. When I double click on an instantiation of that type, a menu appears that contains the default properties of the type "Requirement". It contains some tabs (e.g. the "Files" tab) that are useless to me.
Is there a way to eliminate this tabs?
How can I modify the default tabs of the properties dialog (open by double click on an element)?
A word of warning: be careful when stereotyping Requirements - the relationship between the element stereotype and the requirement types configured into the project (Settings - Project Types) is a bit murky.
That said, there is no way to modify EA's dialogs. What you can do is create your own property dialog and have EA open that when the user double-clicks the element.
In order to achieve this, you need to create an Add-In which catches the Context Item Event EA_OnContextItemDoubleClicked. In your event handler, return true to inform EA that you're handling the event (which prevents EA from opening the default property dialog), and open your own custom dialog.
The same event is fired when the user hits Enter with the element selected. The default property dialog can still be opened by pressing Alt-Enter.
As an alternative, you might want to look into the third-party extension eaForms, which allows you to create your own custom property dialogs without writing your own Add-In.

Use default Common Navigator Action Set for IResource wrapper class

I am developing an Eclipse Plugin.
My View extends CommonNavigator.
the View's contents is an hierarchy of MyWrapper classes
class MyWrapper implement IAdaptable{
IResource resource;
MyWrapper parent;
List<MyWrapper> children;
}
I want to display PopUp menu the same as the Default Common Navigator displays.
I have registered an AdapterFactory that adapt MyWrapper to IResource.
List of actions that are displayed:
New
Remove from context (disabled)
Import
Export
Refresh
Validate
Team
Compare with
Restore from Local History
Properties
List of actions that I need for menu:
Copy
Paste
Rename
does anybody know how to do this?
This tutorial explains how to add those actions: Building a Common Navigator based viewer, Part I: Defining the Viewer Search for the part which adds the "org.eclipse.ui.navigator.resources.*"

overriding setResponsePage() to build breadcrumb

I 'm trying to build my own simple breadcrumb component that pushes a PageRefence onto a List for each and every Link in the application.
Unfortunately, setResponsePage() is final (I use wicket 6).
The only other option that comes to my mind is to add a parameter to my base page constructor. But this would require me to change every link in the app..
Are there any other options?
Since you already have a base page, it's easier to override onBeforeRender() in your base page to update the breadcrumbs list that you'd store in your Session object.
Or am I missing something?
To answer my own question:
In the end I realized, that I do not want to have the breadcrumb updated on each new page.
Therefore I created an object that holds a List of Pagereferences. When I navigate to a new Page, I take the list of the current page, make a copy of it an add the current page. The resulting list is pased onto the new page.
All this is handeld in the base page.
Keeping it in the page, avoids problems with multiple tabs / windows.
Thanks for the help.

Opening IProject properties when another (adaptable to IProject) object is selected

I have a custom view displaying a hierarchy model of the current project. The root element is of class MyProject which is my own class, but it represents one Eclipse IProject, and it's adaptable to IProject.
I have a "properties" menu option in the popup menu for that view, and I'd like to open up IProject's properties when a MyProject object is selected. PropertyDialogAction only looks for property pages registered for MyProject and doesn't give me a chance to offer an adapter -- or, at least, I don't know how to offer one.
What's the proper solution for this?
In the meantime, I've overridden PropertyDialogAction to handle my class in the special way I require, but that seems like quite a kludge to get this done.
How did you add the Properties in the Popup menu? Ideally its functionality is to show up the property pages of the current selection - not to show up the properties of the project in which the current selection resides. If you want that, you need to use the menu item Project->Properties - which uses the ProjectPropertyDialogAction instead of the PropertyDialogAction