KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > ui > refactoring > model > AbstractSynchronizationLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ltk.ui.refactoring.model;
12
13 import org.eclipse.team.core.diff.IDiff;
14 import org.eclipse.team.core.diff.IThreeWayDiff;
15 import org.eclipse.team.ui.mapping.SynchronizationLabelProvider;
16
17 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
18 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
19
20 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorDiff;
21 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy;
22 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringHistoryDiff;
23
24 /**
25  * Partial implementation of a refactoring-aware synchronization label provider.
26  * <p>
27  * This class overrides several methods from
28  * {@link SynchronizationLabelProvider} to customize the rendering of
29  * refactoring history objects in team synchronization views.
30  * </p>
31  * <p>
32  * Note: this class is designed to be extended by clients. Programming language
33  * implementers who need refactoring support in a synchronization label provider
34  * used in team synchronization views may use this class as a basis for
35  * refactoring-aware synchronization label providers.
36  * </p>
37  *
38  * @see org.eclipse.team.ui.mapping.SynchronizationLabelProvider
39  *
40  * @since 3.2
41  */

42 public abstract class AbstractSynchronizationLabelProvider extends SynchronizationLabelProvider {
43
44     /**
45      * {@inheritDoc}
46      */

47     protected String JavaDoc decorateText(final String JavaDoc base, final Object JavaDoc element) {
48         if (element instanceof RefactoringDescriptorProxy)
49             return base;
50         return super.decorateText(base, element);
51     }
52
53     /**
54      * {@inheritDoc}
55      */

56     protected IDiff getDiff(final Object JavaDoc element) {
57         if (element instanceof RefactoringDescriptorProxy)
58             return new RefactoringDescriptorDiff((RefactoringDescriptorProxy) element, getKind(element), getDirection(element));
59         else if (element instanceof RefactoringHistory)
60             return new RefactoringHistoryDiff((RefactoringHistory) element, getKind(element), getDirection(element));
61         return super.getDiff(element);
62     }
63
64     /**
65      * Returns the direction of the difference of the specified refactoring
66      * history object.
67      * <p>
68      * The result of this method is used to compose an icon which reflects the
69      * direction of the difference between the two or three versions of the
70      * refactoring history object.
71      * </p>
72      *
73      * @param element
74      * the refactoring history object
75      * @return the direction of the difference
76      *
77      * @see IThreeWayDiff#getDirection()
78      */

79     protected int getDirection(Object JavaDoc element) {
80         if (element instanceof RefactoringHistory) {
81             final RefactoringHistory history= (RefactoringHistory) element;
82             final RefactoringDescriptorProxy[] descriptors= history.getDescriptors();
83             int direction= 0;
84             if (descriptors.length > 0) {
85                 if (descriptors[0] instanceof RefactoringDescriptorSynchronizationProxy) {
86                     final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) descriptors[0];
87                     direction= proxy.getDirection();
88                 }
89             }
90             for (int index= 1; index < descriptors.length; index++) {
91                 if (descriptors[index] instanceof RefactoringDescriptorSynchronizationProxy) {
92                     final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) descriptors[index];
93                     if (proxy.getDirection() != direction)
94                         return IThreeWayDiff.CONFLICTING;
95                 }
96             }
97             return IDiff.NO_CHANGE;
98         } else if (element instanceof RefactoringDescriptorSynchronizationProxy) {
99             final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) element;
100             return proxy.getDirection();
101         }
102         return IThreeWayDiff.CONFLICTING;
103     }
104
105     /**
106      * Returns the kind of difference between the three sides ancestor, left and
107      * right of the specified refactoring history object.
108      * <p>
109      * The result of this method is used to compose an icon which reflects the
110      * kind of difference between the two or three versions of the refactoring
111      * history object.
112      * </p>
113      *
114      * @param element
115      * the refactoring history object
116      * @return the kind of difference
117      *
118      * @see IDiff#getKind()
119      */

120     protected int getKind(Object JavaDoc element) {
121         if (element instanceof RefactoringHistory)
122             return IDiff.CHANGE;
123         return IDiff.ADD;
124     }
125 }
126
Popular Tags