KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > ui > history > HistoryPageSaveablePart


1 /*******************************************************************************
2  * Copyright (c) 2006 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 package org.eclipse.team.ui.history;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.compare.CompareConfiguration;
16 import org.eclipse.compare.IContentChangeNotifier;
17 import org.eclipse.compare.structuremergeviewer.ICompareInput;
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jface.action.ToolBarManager;
21 import org.eclipse.jface.viewers.*;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.widgets.*;
24 import org.eclipse.team.internal.ui.Utils;
25 import org.eclipse.team.internal.ui.history.DialogHistoryPageSite;
26 import org.eclipse.team.ui.PageSaveablePart;
27 import org.eclipse.team.ui.SaveablePartDialog;
28 import org.eclipse.ui.part.Page;
29
30 /**
31  * Displays a history page combined with the compare/merge infrastructure. This only works properly if the
32  * history page adapts to an {@link IHistoryCompareAdapter}.
33  *
34  * @deprecated use {@link HistoryPageCompareEditorInput}
35  * @since 3.2
36  */

37 public class HistoryPageSaveablePart extends PageSaveablePart {
38
39     private IHistoryPage historyPage;
40     private DialogHistoryPageSite site;
41     private final Object JavaDoc object;
42     private final IHistoryPageSource pageSource;
43     
44     /**
45      * Show the history for the object in a dialog. The history will only be
46      * shown if an {@link IHistoryPageSource} can be found for the object.
47      * @param shell the parent sell
48      * @param object the object
49      * @return whether the object had an {@link IHistoryPageSource} available or not
50      */

51     public static boolean showHistoryInDialog(Shell shell, Object JavaDoc object) {
52         IHistoryPageSource pageSource = HistoryPageSource.getHistoryPageSource(object);
53         if (pageSource != null && pageSource.canShowHistoryFor(object)) {
54             CompareConfiguration cc = new CompareConfiguration();
55             cc.setLeftEditable(isFile(object));
56             cc.setRightEditable(false);
57             HistoryPageSaveablePart input = new HistoryPageSaveablePart(shell, cc, pageSource, object);
58             try {
59                 SaveablePartDialog cd = new SaveablePartDialog(shell, input);
60                 cd.setBlockOnOpen(true);
61                 cd.open();
62             } finally {
63                 input.dispose();
64             }
65             return true;
66         }
67         return false;
68     }
69
70     private static boolean isFile(Object JavaDoc object) {
71         IResource resource = Utils.getResource(object);
72         return (resource != null && resource.getType() == IResource.FILE);
73     }
74     
75     /**
76      * Create a history page part for the given page and object.
77      * @param shell the parent shell
78      * @param configuration the compare configuration
79      * @param pageSource the page source
80      * @param object the object whose history is to be displayed
81      */

82     public HistoryPageSaveablePart(Shell shell, CompareConfiguration configuration, IHistoryPageSource pageSource, Object JavaDoc object) {
83         super(shell,configuration);
84         this.pageSource = pageSource;
85         this.object = object;
86     }
87     /* (non-Javadoc)
88      * @see org.eclipse.team.ui.PageSaveablePart#getTitle()
89      */

90     public String JavaDoc getTitle() {
91         return historyPage.getName();
92     }
93
94     /* (non-Javadoc)
95      * @see org.eclipse.team.ui.PageSaveablePart#getTitleImage()
96      */

97     public Image getTitleImage() {
98         return null;
99     }
100
101     /* (non-Javadoc)
102      * @see org.eclipse.compare.IContentChangeListener#contentChanged(org.eclipse.compare.IContentChangeNotifier)
103      */

104     public void contentChanged(IContentChangeNotifier source) {
105     }
106     
107     /* (non-Javadoc)
108      * @see org.eclipse.team.ui.PageSaveablePart#createPage(org.eclipse.swt.widgets.Composite, org.eclipse.jface.action.ToolBarManager)
109      */

110     protected Control createPage(Composite parent, ToolBarManager toolBarManager) {
111         site = new DialogHistoryPageSite(getShell());
112         historyPage = (IHistoryPage)pageSource.createPage(object);
113         historyPage.setSite(site);
114         site.setToolBarManager(toolBarManager);
115         ((Page) historyPage).createControl(parent);
116         historyPage.setInput(object);
117         String JavaDoc description = historyPage.getDescription();
118         if (description == null)
119             description = ""; //$NON-NLS-1$
120
setPageDescription(description);
121         return ((Page) historyPage).getControl();
122     }
123     
124     /* (non-Javadoc)
125      * @see org.eclipse.team.ui.PageSaveablePart#getPageSelectionProvider()
126      */

127     protected final ISelectionProvider getSelectionProvider() {
128         return site.getSelectionProvider();
129     }
130     
131     /* (non-Javadoc)
132      * @see org.eclipse.team.ui.PageSaveablePart#getCompareInput(org.eclipse.jface.viewers.ISelection)
133      */

134     protected ICompareInput getCompareInput(ISelection selection) {
135         ICompareInput compareInput = super.getCompareInput(selection);
136         if (compareInput != null)
137             return compareInput;
138         IHistoryCompareAdapter compareAdapter = (IHistoryCompareAdapter) Utils.getAdapter(historyPage, IHistoryCompareAdapter.class);
139         if (compareAdapter != null){
140             if (selection instanceof IStructuredSelection) {
141                 IStructuredSelection ss= (IStructuredSelection) selection;
142                 if (ss.size() == 1) {
143                     Object JavaDoc o = ss.getFirstElement();
144                     return compareAdapter.getCompareInput(o);
145                 }
146             }
147         }
148         return null;
149     }
150     
151     /* (non-Javadoc)
152      * @see org.eclipse.team.ui.PageSaveablePart#prepareInput(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.CompareConfiguration, org.eclipse.core.runtime.IProgressMonitor)
153      */

154     protected void prepareInput(ICompareInput input, CompareConfiguration configuration, IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
155         IHistoryCompareAdapter compareAdapter = (IHistoryCompareAdapter) Utils.getAdapter(historyPage, IHistoryCompareAdapter.class);
156         if (compareAdapter != null){
157             compareAdapter.prepareInput(input, configuration, monitor);
158         }
159     }
160     
161     /* (non-Javadoc)
162      * @see org.eclipse.team.ui.SaveablePartAdapter#dispose()
163      */

164     public void dispose() {
165         super.dispose();
166         if (historyPage != null)
167             historyPage.dispose();
168     }
169 }
170
Popular Tags