How to programmatically customize perspective [message #645088] |
Wed, 15 December 2010 09:52  |
Eclipse User |
|
|
|
Hi, I'm extending Eclipse using the Eclipse plug-in infrastructure, and I've come into a problem:
I would like to modify the visibility of my "Menu" (defined in my plugin.xml) programmatically depending on an preferences. Example: When my variable is TRUE. We do: getMenu("ID").setVisible("true"); (just an example)
Is this Possible? if yes, How can I do it?
I found that we can use the class "ApplicationActionBarAdvisor" or "ApplicationWorkbenchWindowAdvisor " to SHOW or HIDE actionSet, using:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
window.getActivePage().hideActionSet(actionSetID); window.getActivePage().showActionSet(actionSetID);
But I don't know how to use this class? wHere must I defind it in my plugin? in Activator.java?
Some help, please.
Best regards. Imen.
|
|
|
Re: How to programmatically customize perspective [message #645144 is a reply to message #645088] |
Wed, 15 December 2010 11:56   |
Eclipse User |
|
|
|
Hi Imen,
sure you can do that. But I suggest a different approach.
Let's see if it works for your needs.
To begin with you have to extend AbstractSourceProvider, here is an example:
package com.rcpvision;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.ui.AbstractSourceProvider;
import org.eclipse.ui.ISources;
public class SessionSourceProvider extends AbstractSourceProvider {
public final static String SESSION_USER_CAN_SEE_PREFS = "com.rcpvision.session.user-can-see-preferences";
private final static String CAN_SEE = "canSee";
private final static String CANNOT_SEE = "cannotSee";
boolean canSee = true;
@Override
public String[] getProvidedSourceNames() {
return new String[] { SESSION_USER_CAN_SEE_PREFS };
}
@Override
public Map<String, String> getCurrentState() {
Map<String, String> currentState = new HashMap<String, String>(1);
String currentState1 = canSee ? CAN_SEE : CANNOT_SEE;
currentState.put(SESSION_USER_CAN_SEE_PREFS, currentState1);
return currentState;
}
@Override
public void dispose() {
}
public void setUserCanSeePreferences(boolean canSee) {
if (this.canSee == canSee)
return; // no change
this.canSee = canSee;
String currentState = canSee ? CAN_SEE : CANNOT_SEE;
fireSourceChanged(ISources.WORKBENCH, SESSION_USER_CAN_SEE_PREFS, currentState);
}
}
then define it in plugin.xml
<extension
point="org.eclipse.ui.services">
<sourceProvider
provider="com.rcpvision.SessionSourceProvider">
<variable
name="com.rcpvision.session.user-can-see-preferences"
priorityLevel="workbench">
</variable>
</sourceProvider>
</extension>
use it, again in, in plugin.xml
<menu
label="Show my view">
<command
commandId="org.eclipse.ui.views.showView"
label="My View"
style="push">
<parameter
name="org.eclipse.ui.views.showView.viewId"
value="com.rcpvision.my.view">
</parameter>
<visibleWhen
checkEnabled="false">
<with
variable="com.rcpvision.session.user-can-see-preferences">
<equals
value="canSee">
</equals>
</with>
</visibleWhen>
</command>
</menu>
and ... change the visibility at runtime
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ISourceProviderService service = (ISourceProviderService) window.getService(ISourceProviderService.class);
SessionSourceProvider sessionSourceProvider = (SessionSourceProvider) service.getSourceProvider(SessionSourceProvider.SESSION_USER_CAN_SEE_PREFS);
sessionSourceProvider.setUserCanSeePreferences( true/false );
is this what you were looking for?
Cheers
Vincenzo
Vincenzo Caselli
RCP Vision
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08740 seconds