001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal;
011:
012: import java.util.Set;
013:
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.Status;
016: import org.eclipse.jface.preference.IPreferenceStore;
017: import org.eclipse.ui.IMemento;
018: import org.eclipse.ui.IWorkbenchPage;
019: import org.eclipse.ui.IWorkbenchPreferenceConstants;
020: import org.eclipse.ui.PartInitException;
021: import org.eclipse.ui.internal.util.PrefUtil;
022: import org.eclipse.ui.views.IStickyViewDescriptor;
023: import org.eclipse.ui.views.IViewRegistry;
024:
025: /**
026: * @since 3.3
027: *
028: */
029: public class StickyViewManager implements IStickyViewManager {
030:
031: private IWorkbenchPage page;
032:
033: public StickyViewManager(IWorkbenchPage page) {
034: this .page = page;
035: }
036:
037: public static IStickyViewManager getInstance(IWorkbenchPage page) {
038: IStickyViewManager stickyViewMan;
039: IPreferenceStore preferenceStore = PrefUtil
040: .getAPIPreferenceStore();
041: boolean enable32Behavior = preferenceStore
042: .getBoolean(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR);
043: if (enable32Behavior)
044: stickyViewMan = new StickyViewManager32(page);
045: else
046: stickyViewMan = new StickyViewManager(page);
047:
048: return stickyViewMan;
049: }
050:
051: /*
052: * (non-Javadoc)
053: *
054: * @see org.eclipse.ui.internal.IStickyViewManager#add(java.lang.String,
055: * java.util.Set)
056: */
057: public void add(String perspectiveId, Set stickyViewSet) {
058: // do nothing
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see org.eclipse.ui.internal.IStickyViewManager#clear()
065: */
066: public void clear() {
067: // do nothing
068: }
069:
070: /*
071: * (non-Javadoc)
072: *
073: * @see org.eclipse.ui.internal.IStickyViewManager#remove(java.lang.String)
074: */
075: public void remove(String perspectiveId) {
076: // do nothing
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see org.eclipse.ui.internal.IStickyViewManager#restore(org.eclipse.ui.IMemento)
083: */
084: public void restore(IMemento memento) {
085: // do nothing
086: }
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see org.eclipse.ui.internal.IStickyViewManager#save(org.eclipse.ui.IMemento)
092: */
093: public void save(IMemento memento) {
094: // do nothing
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see org.eclipse.ui.internal.IStickyViewManager#update(org.eclipse.ui.internal.Perspective,
101: * org.eclipse.ui.internal.Perspective)
102: */
103: public void update(Perspective oldPersp, Perspective newPersp) {
104: if (oldPersp == null || newPersp == null) {
105: return;
106: }
107: IViewRegistry viewReg = WorkbenchPlugin.getDefault()
108: .getViewRegistry();
109: IStickyViewDescriptor[] stickyDescs = viewReg.getStickyViews();
110: for (int i = 0; i < stickyDescs.length; i++) {
111: final String viewId = stickyDescs[i].getId();
112: try {
113: // show a sticky view if it was in the last perspective and
114: // hasn't already been activated in this one
115: if (oldPersp.findView(viewId) != null) {
116: page.showView(viewId, null,
117: 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: }
|