KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > StickyViewManager


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.ui.internal;
13
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.jface.preference.IPreferenceStore;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.IWorkbenchPage;
21 import org.eclipse.ui.IWorkbenchPreferenceConstants;
22 import org.eclipse.ui.PartInitException;
23 import org.eclipse.ui.internal.util.PrefUtil;
24 import org.eclipse.ui.views.IStickyViewDescriptor;
25 import org.eclipse.ui.views.IViewRegistry;
26
27 /**
28  * @since 3.3
29  *
30  */

31 public class StickyViewManager implements IStickyViewManager {
32     
33     private IWorkbenchPage page;
34     
35     public StickyViewManager(IWorkbenchPage page) {
36         this.page = page;
37     }
38
39     
40     public static IStickyViewManager getInstance(IWorkbenchPage page) {
41         IStickyViewManager stickyViewMan;
42         IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
43         boolean enable32Behavior = preferenceStore
44                 .getBoolean(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR);
45         if (enable32Behavior)
46             stickyViewMan = new StickyViewManager32(page);
47         else
48             stickyViewMan = new StickyViewManager(page);
49         
50         return stickyViewMan;
51     }
52     
53     /*
54      * (non-Javadoc)
55      *
56      * @see org.eclipse.ui.internal.IStickyViewManager#add(java.lang.String,
57      * java.util.Set)
58      */

59     public void add(String JavaDoc perspectiveId, Set JavaDoc stickyViewSet) {
60         // do nothing
61
}
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.eclipse.ui.internal.IStickyViewManager#clear()
67      */

68     public void clear() {
69         // do nothing
70
}
71
72     /*
73      * (non-Javadoc)
74      *
75      * @see org.eclipse.ui.internal.IStickyViewManager#remove(java.lang.String)
76      */

77     public void remove(String JavaDoc perspectiveId) {
78         // do nothing
79
}
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see org.eclipse.ui.internal.IStickyViewManager#restore(org.eclipse.ui.IMemento)
85      */

86     public void restore(IMemento memento) {
87         // do nothing
88
}
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see org.eclipse.ui.internal.IStickyViewManager#save(org.eclipse.ui.IMemento)
94      */

95     public void save(IMemento memento) {
96         // do nothing
97
}
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see org.eclipse.ui.internal.IStickyViewManager#update(org.eclipse.ui.internal.Perspective,
103      * org.eclipse.ui.internal.Perspective)
104      */

105     public void update(Perspective oldPersp, Perspective newPersp) {
106         if (oldPersp == null || newPersp == null) {
107             return;
108         }
109         IViewRegistry viewReg = WorkbenchPlugin.getDefault().getViewRegistry();
110         IStickyViewDescriptor[] stickyDescs = viewReg.getStickyViews();
111         for (int i = 0; i < stickyDescs.length; i++) {
112             final String JavaDoc viewId = stickyDescs[i].getId();
113             try {
114                 // show a sticky view if it was in the last perspective and
115
// hasn't already been activated in this one
116
if (oldPersp.findView(viewId) != null) {
117                     page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
118                 }
119                 // remove a view if it's sticky and its not visible in the old
120
// perspective
121
else if (newPersp.findView(viewId) != null
122                         && oldPersp.findView(viewId) == null) {
123                     page.hideView(newPersp.findView(viewId));
124                 }
125             } catch (PartInitException e) {
126                 WorkbenchPlugin
127                         .log(
128                                 "Could not open view :" + viewId, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open view :" + viewId, e)); //$NON-NLS-1$ //$NON-NLS-2$
129
}
130         }
131     }
132
133 }
134
Popular Tags