How to remove subversive action in Synchronize view? - eclipse

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.

Related

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

In TinyMCE 4.x how do you attach a click event handler to content?

I have been trying many things to attach a click event handler to a selection box in tinymce 4.0.2 content with no success. Does anyone know how to do this in a custom plugin? The following is what I have tried but it is not functioning.
ctr++;
var id = 'vnetforms_elem_'+ctr;
editor.insertContent('<select id="'+id+'"><option>X</option</select>');
tinymce.dom.DOMUtils.bind(tinymce.activeEditor.dom.select('#'+id)[0],'click',function() {
alert('click!');
});
Using jQuery this may help:
$(ed.getBody()).find('#'+id).bind('click', function() {
alert('click!');
});
I have solved my own problem.
It turns out that this was indeed a bug in firefox. When a select element in firefox is marked as editable it doesn't fire events. I was able to resolve this with the following.
ctr++;
var id = 'vnetforms_elem_'+ctr;
editor.insertContent('<select id="'+id+'"></select>');
tinymce.activeEditor.dom.select('#'+id)[0].contentEditable = 'false';
addEvent(tinymce.activeEditor.dom.select('#'+id)[0],'click',function() {
alert('MyClick');
});
Where addEvent is defined in the custom plugin as
var addEvent = function(node,eventName,func){
if ("undefined" == typeof node || null == node) {
} else {
if (!node.ownerDocument.addEventListener && node.ownerDocument.attachEvent) {
node.attachEvent('on' + eventName, func);
} else node.addEventListener(eventName,func,false);
}
}; this.addEvent = addEvent;

Update OpenLayers popup

I am trying to update some popups in my map but I am not able to do that.
Firstly I create some markers, and with the next code, I create a popup associated to them. One popup for each marker:
popFeature = new OpenLayers.Feature(markers, location);
popFeature.closeBox = true;
popFeature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
'autoSize': true
});
popFeature.data.popupContentHTML = "hello";
popFeature.data.overflow = (false) ? "auto" : "hidden";
var markerClick = function (evt) {
if (this.popup == null) {
this.popup = this.createPopup(this.closeBox);
map.addPopup(this.popup);
this.popup.show();
} else {
this.popup.toggle();
}
currentPopup = this.popup;
OpenLayers.Event.stop(evt);
};
mark.events.register("mousedown", popFeature, markerClick);
After that, I add the new marker to my marker layer.
Everything is fine until here, but, I want to update the popupcontentHTML some time later and I don't know how I can access to that value.
I read OL API but I don't understand how to get it. I am lost about features, events, extensions...
I want to know if I can access to that property and write other word.
I answer myself, maybe it helps other people in future:
for(i = 0; i < map.popups.length; i++){
if(map.popups[i].lonlat.lon == marker.lonlat.lon){
map.popups[i].setContentHTML("new content");
}
}
Content will be refreshed at the moment.

Working Set Selection Programmatically in Eclipse

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

How to handle Click event or any other Event in GWT Cloud?

I am using tagcloud_0.4.jar for using Tag Cloud in GWT. Now, when I click on any tag inside the tag cloud, then how can I handle that event or how can I do RPC call when user select any tag from cloud?
Thanks.
Here is an example to catch a ClickEvent on the cloud. But this is a workaround as the library may change. As the developper do not offer to manage events on the cloud neither on tags, this is perhaps for a good reason...
So use this code at your own risk. Pray for no change of the widget's structure DOM. I suggest you to ask the developper some enhancements on its widgets, like managing such events.
final TagCloud cloud = new TagCloud();
cloud.addWord(new WordTag("AAA"));
cloud.addWord(new WordTag("AAA"));
cloud.addWord(new WordTag("BBB"));
cloud.addWord(new WordTag("CCC"));
cloud.addWord(new WordTag("CCC"));
cloud.addWord(new WordTag("CCC"));
cloud.addDomHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// Prevent the click from the tag to be executed
event.preventDefault();
Element e;
// For each tag present in the cloud, look for the one that is triggered
for (int i = 0; i < cloud.getTags().size(); ++i) {
// Gets the element in the cloud, this really is the unsafe part of the code
// if the developer change the dom of its widget
e = DOM.getChild(DOM.getChild(cloud.getElement(), 0), i);
// Is the current element targeted by the event?
if (event.getClientX() >= e.getOffsetLeft() && event.getClientY() >= e.getOffsetTop()
&& event.getClientX() <= e.getOffsetLeft() + e.getOffsetWidth()
&& event.getClientY() <= e.getOffsetTop() + e.getOffsetHeight()) {
// Gets the abstract tag
Tag t = cloud.getTags().get(i);
// Gets tag descendant
if (t instanceof WordTag) {
// Do what you want with your WordTag, maybe an RPC call
} else if (t instanceof ImageTag) {
// Do what you want with your ImageTag, maybe an RPC call
}
break;
}
}
}
}, ClickEvent.getType());