KickJava   Java API By Example, From Geeks To Geeks.

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


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.IThreeWayDiff;
14 import org.eclipse.team.core.mapping.ISynchronizationContext;
15 import org.eclipse.team.ui.mapping.SynchronizationCompareAdapter;
16
17 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
18
19 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorCompareInput;
20 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy;
21
22 import org.eclipse.compare.structuremergeviewer.Differencer;
23 import org.eclipse.compare.structuremergeviewer.ICompareInput;
24
25 /**
26  * Partial implementation of a refactoring-aware synchronization compare adapter.
27  * <p>
28  * This class provides compare support for the refactoring history objects
29  * associated with a refactoring model provider.
30  * </p>
31  * <p>
32  * Note: this class is designed to be extended by clients. Programming language
33  * implementers which need a refactoring-aware synchronization compare adapter to contribute to
34  * team synchronization views may extend this class to provide specific compare
35  * inputs for their model elements.
36  * </p>
37  *
38  * @see SynchronizationCompareAdapter
39  *
40  * @since 3.2
41  */

42 public abstract class AbstractSynchronizationCompareAdapter extends SynchronizationCompareAdapter {
43
44     /**
45      * {@inheritDoc}
46      */

47     public ICompareInput asCompareInput(final ISynchronizationContext context, final Object JavaDoc element) {
48         if (element instanceof RefactoringDescriptorProxy)
49             return new RefactoringDescriptorCompareInput((RefactoringDescriptorProxy) element, getKind(context, (RefactoringDescriptorProxy) element));
50         return super.asCompareInput(context, element);
51     }
52
53     /**
54      * Returns the kind of difference between the three sides ancestor, left and
55      * right of the specified refactoring descriptor proxy.
56      * <p>
57      * The result of this method is used to compose an icon which reflects the
58      * kind of difference between the two or three versions of the refactoring
59      * descriptor.
60      * </p>
61      *
62      * @param context
63      * the synchronization context
64      * @param proxy
65      * the refactoring descriptor proxy
66      * @return the kind of difference
67      *
68      * @see ICompareInput#getKind()
69      */

70     protected int getKind(final ISynchronizationContext context, final RefactoringDescriptorProxy proxy) {
71         int kind= Differencer.ADDITION;
72         if (proxy instanceof RefactoringDescriptorSynchronizationProxy) {
73             final RefactoringDescriptorSynchronizationProxy extended= (RefactoringDescriptorSynchronizationProxy) proxy;
74             final int direction= extended.getDirection();
75             if (direction == IThreeWayDiff.OUTGOING)
76                 kind|= Differencer.LEFT;
77             else if (direction == IThreeWayDiff.INCOMING)
78                 kind|= Differencer.RIGHT;
79         }
80         return kind;
81     }
82 }
83
Popular Tags