Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Update workbench when active perspective changes
Update workbench when active perspective changes [message #462111] Tue, 23 January 2007 09:48
Christoph is currently offline ChristophFriend
Messages: 55
Registered: July 2009
Member
------=_Part_482_31792324.1169545740090
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

i have the following problem. I=B4m looking for a solution for a couple of =
hours but i can=B4t come up with a solution so far.=20

I have a rcp-application with two perspectives. When the active perspective=
is changed i want several thing within the workbench to be changed. So i h=
ave written a PerspectiveListener and registered it with the WorkbenchWindo=
w. This works fine, the listener gets notified and i have the Objects of th=
e window and the new perspective. Everything is prepared. But i can=B4t fig=
ure out how to do the following:

- the toolbar of the window should be hidden
- the perspective-bar should be hidden
- one entry in the main-menu should be hidden

And i have one view with a JFace-Treeviewer in it. I want the entries in th=
is treeviewer to be updated depending on the new perspective. So i called c=
reatePartControl() on that view, my model is created again with the new ent=
ries and set as the input of the treeviewer, i even called refresh() on the=
treeviewer, but nothing happens. I can debug this and see that the model i=
s created correctly and that it is set, but the view is not updated.

And i attach the View-Class and my PerspectiveListener for you reference.=
=20

Can anybody here help me out with one of this things? Thanks very much in a=
dvance for any help.
Christoph
------=_Part_482_31792324.1169545740090
Content-Type: application/octet-stream; name=mainview.java
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=mainview.java

cGFja2FnZSBkZS5nZWJpdG1zLmdlcGxhbi51aS52aWV3czsNCg0KaW1wb3J0 IG9yZy5lY2xpcHNl
LmNvcmUucnVudGltZS5JQWRhcHRlckZhY3Rvcnk7DQppbXBvcnQgb3JnLmVj bGlwc2UuY29yZS5y
dW50aW1lLlBsYXRmb3JtOw0KaW1wb3J0IG9yZy5lY2xpcHNlLmpmYWNlLnZp ZXdlcnMuVHJlZVZp
ZXdlcjsNCmltcG9ydCBvcmcuZWNsaXBzZS5zd3QuU1dUOw0KaW1wb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2VwbGFu
LnZpZXcubWFpbi5ncnVwcGU3IiksNyk7IA0KCQkJcm9vdC5hZGRFbnRyeShn cnVwcGU3KTsNCiAg
ICAgICAgfQ0KICAgIH0NCg0KCS8qKg0KCSAqIEBzZWUgb3JnLmVjbGlwc2Uu dWkucGFydC5Xb3Jr
YmVuY2hQYXJ0I3NldEZvY3VzKCkNCgkgKi8NCglwdWJsaWMgdm9pZCBzZXRG b2N1cygpIHsNCgkJ
dHJlZVZpZXdlci5nZXRDb250cm9sKCkuc2V0Rm9jdXMoKTsNCgl9DQp9DQo=
------=_Part_482_31792324.1169545740090
Content-Type: application/octet-stream; name=perspectivelistener.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=perspectivelistener.java

package de.gebitms.geplan.ui.listeners;

import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PerspectiveAdapter;
import de.gebitms.geplan.global.GlobalTokens;
import de.gebitms.geplan.ui.views.MainView;

/**
* Listener f\u00FCr Ereignisse im Zusammenhang mit Perspektiven
* @author Christoph
*/
public class PerspectiveListener extends PerspectiveAdapter {

private IWorkbenchWindow window;

/**
* Erstellt den Listener f\u00FCr ein gegebenes Fenster
* @param window Das Fenster, das beobachtet werden soll
*/
public PerspectiveListener(IWorkbenchWindow window) {
this.window = window;
window.addPerspectiveListener(this);
}

/**
* Disposes the tracker.
*/
public void dispose() {
if (window != null) {
window.removePerspectiveListener(this);
}
}

public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
update(perspective);
}

/**
* F\u00FChrt die Aktualisierungen durch, in Abh\u00E4ngigkeit von der aktuellen Perspektive
* @param persp Die aktive Perspektive im Fenster
*/
protected void update(IPerspectiveDescriptor persp) {
// Ermitteln, um welche Perspektive es sich handelt
// 1=Admin, 2=User
int ps_art=(persp.getId()==GlobalTokens.PERSPECTIVE_ADMIN)?1:2;

// Je nach Perspektive vorgahen
switch (ps_art){
case 1:

break;
case 2:

break;
}
// Alle Views im Fenster aktualisieren
for (Object view:window.getActivePage().getViewReferences()){
IViewReference viewRef=(IViewReference)view;
if (viewRef.getId().equals("de.gebitms.geplan.ui.views.Main")){
MainView mainView=(MainView)viewRef.getView(true);
if(mainView!=null) mainView.createPartControl(mainView.getSite().getShell());
}
}
}

}
------=_Part_482_31792324.1169545740090--
Previous Topic:Updating Workbench when perspective changes
Next Topic:how to determine all plugins
Goto Forum:
  


Current Time: Sat Sep 07 10:54:31 GMT 2024

Powered by FUDForum. Page generated in 0.03338 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top