|
Re: How to programmatically customize perspective [message #645144 is a reply to message #645088] |
Wed, 15 December 2010 16:56 |
Vincenzo Caselli Messages: 51 Registered: July 2009 |
Member |
|
|
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
|
|
|
Re: How to programmatically customize perspective [message #645636 is a reply to message #645144] |
Sun, 19 December 2010 09:58 |
KHALFAOUI Imen Messages: 9 Registered: April 2010 |
Junior Member |
|
|
Hi Vincenzo,
Thank's for your reply.
I just have a question regarding this solution. Is this allows me to change the visibility of my MENU when Eclipse is running.
For example: According to the parameter MENU_VISIBLE in preference page of my plugin which takes the value "TRUE" or "FALSE". when the user click on "OK" (of the preference page) I do this:
sessionSourceProvider.setUserCanSeePreferences(getValue("MENU_VISIBLE"));
Also, for : "and ... change the visibility at runtime..."
What do you mean by "Runtime"?
I try the "Activator.java" but the "window" (activeWorkbenchWindow) was NULL.
sorry, I'm a beginner in the development of plugins.
Best Regards
[Updated on: Sun, 19 December 2010 10:00] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03199 seconds