KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > CompareOutlinePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.compare.internal;
12
13 import org.eclipse.compare.*;
14 import org.eclipse.compare.structuremergeviewer.ICompareInput;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17 import org.eclipse.jface.viewers.*;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.part.IPageSite;
22 import org.eclipse.ui.part.Page;
23 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
24
25 /**
26  */

27 public class CompareOutlinePage extends Page implements IContentOutlinePage, IPropertyChangeListener {
28
29     private CompareEditor fCompareEditor;
30     private Control fControl;
31     private CompareViewerSwitchingPane fStructurePane;
32     private OutlineViewerCreator fCreator;
33     
34     CompareOutlinePage(CompareEditor editor) {
35         fCompareEditor= editor;
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
40      */

41     public void createControl(Composite parent) {
42         final Splitter h= new Splitter(parent, SWT.HORIZONTAL);
43         fStructurePane= new CompareViewerSwitchingPane(h, SWT.BORDER | SWT.FLAT, true) {
44             protected Viewer getViewer(Viewer oldViewer, Object JavaDoc input) {
45                 if (input instanceof ICompareInput)
46                     return findStructureViewer(oldViewer, (ICompareInput)input, this);
47                 return null;
48             }
49         };
50         h.setVisible(fStructurePane, true);
51         fControl = h;
52         IPageSite site = getSite();
53         site.setSelectionProvider(fStructurePane);
54         h.layout();
55         reset();
56     }
57     
58     private Viewer findStructureViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
59         OutlineViewerCreator creator = getCreator();
60         if (creator != null)
61             return creator.findStructureViewer(oldViewer, input, parent, getCompareConfiguration());
62         return null;
63     }
64
65     private CompareConfiguration getCompareConfiguration() {
66         return fCompareEditor.getCompareConfiguration();
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.ui.part.IPage#getControl()
71      */

72     public Control getControl() {
73         return fControl;
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.ui.part.IPage#setFocus()
78      */

79     public void setFocus() {
80         if (fStructurePane != null)
81             fStructurePane.setFocus();
82     }
83
84     /* (non-Javadoc)
85      * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
86      */

87     public void addSelectionChangedListener(ISelectionChangedListener listener) {
88         if (fStructurePane != null)
89             fStructurePane.addSelectionChangedListener(listener);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
94      */

95     public ISelection getSelection() {
96         if (fStructurePane != null)
97             return fStructurePane.getSelection();
98         return StructuredSelection.EMPTY;
99     }
100
101     /* (non-Javadoc)
102      * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
103      */

104     public void removeSelectionChangedListener(ISelectionChangedListener listener) {
105         if (fStructurePane != null)
106             fStructurePane.removeSelectionChangedListener(listener);
107     }
108
109     /* (non-Javadoc)
110      * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
111      */

112     public void setSelection(ISelection selection) {
113         if (fStructurePane != null)
114             fStructurePane.setSelection(selection);
115     }
116     
117     private void setInput(Object JavaDoc input) {
118         if (fStructurePane != null) {
119             fStructurePane.setInput(input);
120             ((Splitter)fControl).layout();
121         }
122     }
123
124     public OutlineViewerCreator getCreator() {
125         if (fCreator == null) {
126             fCreator = (OutlineViewerCreator)Utilities.getAdapter(fCompareEditor, OutlineViewerCreator.class);
127             if (fCreator != null)
128                 fCreator.addPropertyChangeListener(this);
129         }
130         return fCreator;
131     }
132
133     public void propertyChange(PropertyChangeEvent event) {
134         if (event.getProperty().equals(OutlineViewerCreator.PROP_INPUT)) {
135             fStructurePane.setInput(event.getNewValue());
136             ((Splitter)fControl).layout();
137         }
138     }
139     
140     public void dispose() {
141         super.dispose();
142         if (fCreator != null)
143             fCreator.removePropertyChangeListener(this);
144         fCreator = null;
145     }
146
147     public void reset() {
148         if (fCreator != null)
149             fCreator.removePropertyChangeListener(this);
150         fCreator = null;
151         OutlineViewerCreator creator = getCreator();
152         if (creator != null)
153             setInput(creator.getInput());
154         else
155             setInput(null);
156     }
157 }
158
Popular Tags