1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IPerspectiveDescriptor; 14 import org.eclipse.ui.IPerspectiveListener; 15 import org.eclipse.ui.IPluginContribution; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.PartInitException; 18 import org.eclipse.ui.PlatformUI; 19 import org.eclipse.ui.activities.IIdentifier; 20 import org.eclipse.ui.activities.IIdentifierListener; 21 import org.eclipse.ui.activities.IWorkbenchActivitySupport; 22 import org.eclipse.ui.activities.IdentifierEvent; 23 import org.eclipse.ui.activities.WorkbenchActivityHelper; 24 import org.eclipse.ui.views.IViewDescriptor; 25 26 32 class LayoutHelper { 33 34 37 private LayoutHelper() { 38 } 40 41 57 public static final void addViewActivator(PageLayout pageLayout, 58 final String viewId) { 59 if (viewId == null) { 60 return; 61 } 62 63 ViewFactory viewFactory = pageLayout.getViewFactory(); 64 65 final IWorkbenchPage partPage = viewFactory.getWorkbenchPage(); 66 if (partPage == null) { 67 return; 68 } 69 70 final IPerspectiveDescriptor partPerspective = pageLayout 71 .getDescriptor(); 72 73 IWorkbenchActivitySupport support = PlatformUI.getWorkbench() 74 .getActivitySupport(); 75 76 IViewDescriptor descriptor = viewFactory.getViewRegistry().find(viewId); 77 if (!(descriptor instanceof IPluginContribution)) { 78 return; 79 } 80 81 IIdentifier identifier = support.getActivityManager().getIdentifier( 82 WorkbenchActivityHelper 83 .createUnifiedId((IPluginContribution) descriptor)); 84 85 identifier.addIdentifierListener(new IIdentifierListener() { 86 87 90 public void identifierChanged(IdentifierEvent identifierEvent) { 91 if (identifierEvent.hasEnabledChanged()) { 92 IIdentifier thisIdentifier = identifierEvent 93 .getIdentifier(); 94 if (thisIdentifier.isEnabled()) { 95 thisIdentifier.removeIdentifierListener(this); 97 IWorkbenchPage activePage = partPage 98 .getWorkbenchWindow().getActivePage(); 99 if (partPage == activePage 100 && partPerspective == activePage 101 .getPerspective()) { 102 try { 104 partPage.showView(viewId); 105 } catch (PartInitException e) { 106 WorkbenchPlugin.log(getClass(), "identifierChanged", e); } 108 } else { partPage.getWorkbenchWindow() 110 .addPerspectiveListener( 111 new IPerspectiveListener() { 112 113 116 public void perspectiveActivated( 117 IWorkbenchPage page, 118 IPerspectiveDescriptor newPerspective) { 119 if (partPerspective == newPerspective) { 120 partPage 121 .getWorkbenchWindow() 122 .removePerspectiveListener( 123 this); 124 try { 125 page 126 .showView(viewId); 127 } catch (PartInitException e) { 128 WorkbenchPlugin.log(getClass(), "perspectiveActivated", e); } 130 } 131 } 132 133 136 public void perspectiveChanged( 137 IWorkbenchPage page, 138 IPerspectiveDescriptor perspective, 139 String changeId) { 140 } 142 }); 143 } 144 } 145 } 146 } 147 }); 148 } 149 150 159 public static final ViewPane createView(ViewFactory factory, String viewId) 160 throws PartInitException { 161 WorkbenchPartReference ref = (WorkbenchPartReference) factory 162 .createView(ViewFactory.extractPrimaryId(viewId), ViewFactory 163 .extractSecondaryId(viewId)); 164 ViewPane newPart = (ViewPane) ref.getPane(); 165 return newPart; 166 } 167 168 } 169 | Popular Tags |