I want to achieve the functionality of selecting a working set programmatically. I tried with the below code:
IWorkingSetManager wsMgr = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSet ws = wsMgr.getWorkingSet("custom");
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkingSet[] windowset = new IWorkingSet[]{ws};
page.setWorkingSets(windowset);
But the above code does not work and the Project Explorer does not show the working set.
Why does not the above code work and what is the solution for the above?
For updating the ProjectExplorer view with a working set, I tried the below code
IWorkingSetManager wsMgr = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSet ws = wsMgr.getWorkingSet("custom");
ProjectExplorer pView = (ProjectExplorer)page.findView(IPageLayout.ID_PROJECT_EXPLORER);
pView.getCommonViewer().setInput(ws);
The above code displays the content of the working set in ProjectExplorer, but that is not persisted. I mean once Eclipse is restarted, instead of the working set, all projects are getting displayed.
Here's an example handler I created that can set working sets programmatically in a Project Explorer and turn on top level workingsets if it's not already on:
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow workbenchWindow = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
IWorkbenchPage page = workbenchWindow.getActivePage();
IWorkingSetManager manager = workbenchWindow.getWorkbench()
.getWorkingSetManager();
ProjectExplorer projExplorer = (ProjectExplorer) page
.findView(IPageLayout.ID_PROJECT_EXPLORER);
// This is just a test, to ensure we got hold on the correct object for
// Project Explorer.
// The project explorer will get focus now.
projExplorer.setFocus();
// Obtain list of all existing working sets.
// This assumes that the debug workspace used have some working sets
// prepared.
IWorkingSet[] allExistingSets = manager.getWorkingSets();
IWorkingSet workingSet = null;
// The prints information about all working sets.
for (IWorkingSet myset : allExistingSets) {
workingSet = myset;
IAdaptable[] elems = myset.getElements();
System.out.println("Working set " + myset.getName() + " has "
+ elems.length + " projects.");
for (IAdaptable elem : elems) {
System.out.println("Working set " + myset.getName()
+ " contains " + elem.toString());
}
}
page.setWorkingSets(allExistingSets);
NavigatorActionService actionService = projExplorer
.getNavigatorActionService();
CommonViewer viewer = (CommonViewer) projExplorer
.getAdapter(CommonViewer.class);
INavigatorContentService contentService = viewer
.getNavigatorContentService();
try {
IExtensionStateModel extensionStateModel = contentService
.findStateModel(WorkingSetsContentProvider.EXTENSION_ID);
extensionStateModel.setBooleanProperty(
WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS,
true);
projExplorer.setRootMode(ProjectExplorer.WORKING_SETS);
WorkingSetActionProvider provider = (WorkingSetActionProvider) getActionProvider(
contentService, actionService,
WorkingSetActionProvider.class);
IPropertyChangeListener l = provider.getFilterChangeListener();
PropertyChangeEvent pevent = new PropertyChangeEvent(this,
WorkingSetFilterActionGroup.CHANGE_WORKING_SET, null,
page.getAggregateWorkingSet());
l.propertyChange(pevent);
viewer.refresh();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static CommonActionProvider getActionProvider(
INavigatorContentService contentService,
NavigatorActionService actionService, Class cls) throws Exception {
CommonActionProvider provider = null;
CommonActionProviderDescriptor[] providerDescriptors = CommonActionDescriptorManager
.getInstance().findRelevantActionDescriptors(contentService,
new ActionContext(new StructuredSelection()));
if (providerDescriptors.length > 0) {
for (int i = 0; i < providerDescriptors.length; i++) {
provider = actionService
.getActionProviderInstance(providerDescriptors[i]);
if (provider.getClass() == cls)
return provider;
}
}
return null;
}
It doesn't reset the radio button in the view menu for Top Level Elements though. It also has to use internals to work.
After setting the new working sets into the active page. Did you change your project explorer view into working sets mode?
Please find the project explorer view and do set the mode.
ProjectExplorer projExplorer = (ProjectExplorer) page.findView(IPageLayout.ID_PROJECT_EXPLORER);
projExplorer.setRootMode(ProjectExplorer.WORKING_SETS);
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");
}
}
}
So I'm trying to get the Dialog have the same style as the rest of the Eclipse.
This input is triggered when a button on a menu is pressed.
Here is my code right now , but the Dialog looks the same with null instead of (Component) win as parameter.
// JFrame frame = new JFrame ("Something");
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
while (b != true) {
userInput = (String) JOptionPane.showInputDialog((Component) win, "Entersomething", "GDB Server Connection Port:", JOptionPane.DEFAULT_OPTION, null,null,2345);
if (userInput != null && userInput.matches("[0-9]+")) {
b = true; }
else {
JOptionPane.showMessageDialog(Component) win, "Please enter valid input","Error",JOptionPane.WARNING_MESSAGE);
}
}
return userInput ;
Use LookAndFeel to have same style in whole application instead:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EDIT:
Have a look at this then:
http://www.programcreek.com/java-api-examples/index.php?api=org.eclipse.swt.widgets.MessageBox
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DialogExamples.htm
http://www.vogella.com/tutorials/EclipseDialogs/article.html
I am developing an RCP application, I wanted to set the status line. I figured out that I can extend the ActionBarAdvisor class and by overriding the method fillStatusLine() method I can set the status.
private StatusLineContributionItem statusItem;
#Override
protected void fillStatusLine(IStatusLineManager statusLine) {
statusItem = new StatusLineContributionItem("LoggedInStatus");
statusItem.setText("Logged in");
statusLine.add(statusItem);
}
Now, I wish to set image along with it. Is is possible to add image to status line?
You need to override fill(Composite parent) method in your StatusLineContributionItem. There you can add custom components (images, buttons etc. to a status line). For example: http://book.javanb.com/eclipse-rich-client-platform-designing-coding-and-packaging-java-applications-oct-2005/ch17lev1sec7.html
org.eclipsercp.hyperbola/StatusLineContribution
public void fill(Composite parent) {
Label separator = new Label(parent, SWT.SEPARATOR);
label = new CLabel(parent, SWT.SHADOW_NONE);
GC gc = new GC(parent);
gc.setFont(parent.getFont());
FontMetrics fm = gc.getFontMetrics();
Point extent = gc.textExtent(text);
if (widthHint > 0)
widthHint = fm.getAverageCharWidth() * widthHint;
else
widthHint = extent.x;
heightHint = fm.getHeight();
gc.dispose();
StatusLineLayoutData statusLineLayoutData = new StatusLineLayoutData();
statusLineLayoutData.widthHint = widthHint;
statusLineLayoutData.heightHint = heightHint;
label.setLayoutData(statusLineLayoutData);
label.setText(text);
label.setImage(image);
...
}
You chould use the following class: org.eclipse.ui.texteditor.StatusLineContributionItem.class this contains the method setImage(Image image).
It is found in: plugins/org.eclipse.ui.workbench.texteditor_(version).jar of your eclipse installation.
This is class extends: org.eclipse.jface.action.StatusLineContributionItem.class.
Note there are 2 classes named: StatusLineContributionItem.class the other resides in: plugins/org.eclipse.jface_(version).jar and is named: org.eclipse.jface.action.StatusLineContributionItem.class.
This one however does not contain the setImage(Image image) method.
You can then call:
StatusLineManager statusLine = new StatusLineManager();
StatusLineContributionItem i = new StatusLineContributionItem("myid");
i.setText("myText");
i.setImage(SWTResourceManager.getImage(MyClass.class, "config.gif");
...
statusLine.add(i);
...
return statusLine;
If you want complete customization you can use the solution above overriding the fill(Composite composite) method.
Reference:
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fui%2Ftexteditor%2FStatusLineContributionItem.html
I have developed an application using net bean,
1) I'm making project in java API 6. I'm using "Net Beans 7.1".
2) I want to use JInternalFrame in my project
3) I made another package and made "JInternalFrame" there. And then call it in my main application window by firing action performed event on "JMenuItem".
4) It works fine but only one problem occurs that is, if i click on "JMenuItem" again and again, new "JInternalFrame" of same instance are opening, How can i stop that?
5) I want that, if I open "JInternalFrame" once and then i again click on "JMenuItem" to open the same "JInternalFrame", it Should do nothing or it shows the window which already opened and minimized
sample code:
<code>
private void empDataActionPerformed(java.awt.event.ActionEvent evt) {
Emps employees = new Emps();
desktop.add(employees);
employees.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
employees.setBounds(230, 40, screenSize.width / 2 - 80, screenSize.height / 2 + 105);
}
<code>
please I need help.
Here is may sample code. hope this help.
Menu action to call internal frame in main application where JdesktopPane in it.
private void YourJinternalFrameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
YourJinternalFrame nw = YourJinternalFrame.getInstance();
nw.pack();
//usefull part for you.. if open shows, if not creates new one
if (nw.isVisible()) {
} else {
desktopPane.add(nw);
nw.setVisible(true);
}
try {
nw.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex);
}
}
put this inside of your YourJinternalFrame
private static YourJinternalFrame myInstance;
public static YourJinternalFrame getInstance() {
if (myInstance == null) {
myInstance = new YourJinternalFrame();
}
return myInstance;
I'm integrating Subversive 0.7.8 into an Eclipse Platform 3.4.2 RCP app.
I want to remove (or disable) the SVN "Commit" action in the popup menu of the "Synchronize" view.
How can I do ... ?
Thank you for your help.
JM.D
Why would you need to do that ?
Can't you simply make it that your users don't have the right to commit using svn rights ?
Two ways: Either alter the plugin.xml files inside the plugins from subversion to remove the contributions (which means that you have to keep your own version of the plugins), or you can remove specific contributions from the platform.
The removal normally takes place in the class that extends the IApplication interface, before you launch the actual Platform.
This is basically a hack, but it will allow you to do what you want without touching the subversion plugins. I don't know the names of the contributions (You would have to look them up in the source code from the plugins) but the code looks like:
IExtensionRegistry extensionRegistry = InternalPlatform.getDefault().getRegistry();
List uiExtensionsToRemove = Arrays.toList(new String[] {"org.eclipse.ui.views.ProgressView" }); // Removing the progress view in this example
String[] tmpNamespaces = extensionRegistry.getNamespaces();
for (int i = 0; i < tmpNamespaces.length; i++) {
String tmpNamespace = tmpNamespaces[i];
try {
IExtension[] tmpExtensions = extensionRegistry.getExtensions(tmpNamespace);
for (int j = 0; j < tmpExtensions.length; j++) {
IExtension tmpExtension = tmpExtensions[j];
ExtensionHandle tmpEHandle = (ExtensionHandle)tmpExtension;
String tmpEPUID = tmpEHandle.getExtensionPointUniqueIdentifier();
if ("org.eclipse.search.searchPages".equals(tmpEPUID) || "org.eclipse.ui.preferencePages".equals(tmpEPUID) || "org.eclipse.ui.popupMenus".equals(tmpEPUID) || "org.eclipse.ui.actionSets".equals(tmpEPUID)
|| "org.eclipse.ui.views".equals(tmpEPUID) || "org.eclipse.ui.perspectives".equals(tmpEPUID)) {
// only remove part of ui extensions
if (tmpEHandle.getNamespace().startsWith("org.eclipse.ui")) {
String idOfFirstExtension = tmpEHandle.getConfigurationElements()[0].getAttribute("id");
if (!uiExtensionsToRemove.contains(idOfFirstExtension)) {
continue;
}
}
removeExtension(tmpEHandle);
}
} catch (InvalidRegistryObjectException iroe) {
}
//System.out.println("Namespace: " + tmpNamespace);
}
private void removeExtension(ExtensionHandle extensionHandle) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
if (removeExtensionMethod == null) {
removeExtensionMethod = extensionRegistry.getClass().getDeclaredMethod("removeExtension", new Class[] { int.class });
removeExtensionMethod.setAccessible(true);
}
// well, this is some magic:
int tmpExtId = extensionHandle.hashCode();
removeExtensionMethod.invoke(extensionRegistry, new Object[] { new Integer(tmpExtId) });
}
You should certainly check out Activities.