1 11 12 package org.eclipse.ui.internal; 13 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 import java.util.Set ; 19 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.ui.IMemento; 23 import org.eclipse.ui.IWorkbenchPage; 24 import org.eclipse.ui.PartInitException; 25 import org.eclipse.ui.views.IStickyViewDescriptor; 26 import org.eclipse.ui.views.IViewRegistry; 27 28 32 class StickyViewManager32 implements IStickyViewManager { 33 34 private Map stickyPerspectives = new HashMap (7); 37 38 private IWorkbenchPage page; 39 40 public StickyViewManager32(IWorkbenchPage page) { 41 this.page = page; 42 } 43 44 47 public void remove(String pespectiveId) { 48 stickyPerspectives.remove(pespectiveId); 49 } 50 51 54 public void add(String pespectiveId, Set stickyViewList) { 55 stickyPerspectives.put(pespectiveId, stickyViewList); 56 } 57 58 61 public void clear() { 62 stickyPerspectives.clear(); 63 } 64 65 68 public void update(Perspective oldPersp, Perspective newPersp) { 69 if (newPersp != null && oldPersp != null) { 70 Set activatedStickyViewsInThisPerspective = (Set ) stickyPerspectives 71 .get(newPersp.getDesc().getId()); 72 if (activatedStickyViewsInThisPerspective == null) { 73 activatedStickyViewsInThisPerspective = new HashSet (7); 74 stickyPerspectives.put(newPersp.getDesc().getId(), 75 activatedStickyViewsInThisPerspective); 76 } 77 IViewRegistry viewReg = WorkbenchPlugin.getDefault() 78 .getViewRegistry(); 79 IStickyViewDescriptor[] stickyDescs = viewReg.getStickyViews(); 80 for (int i = 0; i < stickyDescs.length; i++) { 81 final String viewId = stickyDescs[i].getId(); 82 try { 83 if (oldPersp.findView(viewId) != null 85 && !activatedStickyViewsInThisPerspective 86 .contains(viewId)) { 87 page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE); 88 activatedStickyViewsInThisPerspective.add(viewId); 89 } 90 } catch (PartInitException e) { 91 WorkbenchPlugin 92 .log( 93 "Could not open view :" + viewId, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open view :" + viewId, e)); } 95 } 96 } 97 } 98 99 102 public void save(IMemento memento) { 103 IMemento stickyState = memento.createChild(IWorkbenchConstants.TAG_STICKY_STATE); 104 Iterator itr = stickyPerspectives.entrySet().iterator(); 105 while (itr.hasNext()) { 106 Map.Entry entry = (Map.Entry ) itr.next(); 107 String perspectiveId = (String ) entry.getKey(); 108 Set activatedViewIds = (Set ) entry.getValue(); 109 IMemento perspectiveState = stickyState.createChild( 110 IWorkbenchConstants.TAG_PERSPECTIVE, perspectiveId); 111 for (Iterator i = activatedViewIds.iterator(); i.hasNext();) { 112 String viewId = (String ) i.next(); 113 perspectiveState.createChild(IWorkbenchConstants.TAG_VIEW, 114 viewId); 115 } 116 } 117 } 118 119 122 public void restore(IMemento memento) { 123 IMemento stickyState = memento 125 .getChild(IWorkbenchConstants.TAG_STICKY_STATE); 126 127 if (stickyState != null) { 128 IMemento[] stickyPerspMems = stickyState 129 .getChildren(IWorkbenchConstants.TAG_PERSPECTIVE); 130 for (int i = 0; i < stickyPerspMems.length; i++) { 131 String perspectiveId = stickyPerspMems[i].getID(); 132 Set viewState = new HashSet (7); 133 stickyPerspectives.put(perspectiveId, viewState); 134 IMemento[] viewStateMementos = stickyPerspMems[i] 135 .getChildren(IWorkbenchConstants.TAG_VIEW); 136 for (int j = 0; j < viewStateMementos.length; j++) { 137 viewState.add(viewStateMementos[j].getID()); 138 } 139 } 140 } 141 } 142 } 143 | Popular Tags |