KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > model > RefactoringDescriptorCompareInput


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.internal.ui.refactoring.model;
12
13 import org.eclipse.team.core.diff.IThreeWayDiff;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.PlatformObject;
17
18 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
19
20 import org.eclipse.ltk.internal.ui.refactoring.RefactoringPluginImages;
21 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages;
22
23 import org.eclipse.swt.graphics.Image;
24
25 import org.eclipse.compare.CompareUI;
26 import org.eclipse.compare.ITypedElement;
27 import org.eclipse.compare.structuremergeviewer.ICompareInput;
28 import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
29
30 /**
31  * Compare input which represents a pending refactoring.
32  *
33  * @since 3.2
34  */

35 public final class RefactoringDescriptorCompareInput extends PlatformObject implements ICompareInput {
36
37     /** Refactoring descriptor element */
38     private final class RefactoringDescriptorElement implements ITypedElement {
39
40         /**
41          * {@inheritDoc}
42          */

43         public Image getImage() {
44             return RefactoringDescriptorCompareInput.this.getImage();
45         }
46
47         /**
48          * {@inheritDoc}
49          */

50         public String JavaDoc getName() {
51             if (fDescriptor instanceof RefactoringDescriptorSynchronizationProxy) {
52                 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) fDescriptor;
53                 if (proxy.getDirection() == IThreeWayDiff.INCOMING)
54                     return ModelMessages.RefactoringDescriptorCompareInput_pending_refactoring;
55                 else
56                     return ModelMessages.RefactoringDescriptorCompareInput_performed_refactoring;
57             }
58             return RefactoringUIMessages.RefactoringWizard_refactoring;
59         }
60
61         /**
62          * {@inheritDoc}
63          */

64         public String JavaDoc getType() {
65             return TYPE_REFACTORING_DESCRIPTOR;
66         }
67     }
68
69     /** Has the image already been registered? */
70     private static boolean fImageRegistered= false;
71
72     /** The refactoring descriptor type */
73     private static final String JavaDoc TYPE_REFACTORING_DESCRIPTOR= "refactoring_descriptor"; //$NON-NLS-1$
74

75     /** The refactoring descriptor */
76     private final RefactoringDescriptorProxy fDescriptor;
77
78     /** The differencer kind */
79     private final int fKind;
80
81     /**
82      * Creates a new refactoring descriptor compare input.
83      *
84      * @param descriptor
85      * the refactoring descriptor
86      * @param kind
87      * the differencer kind
88      */

89     public RefactoringDescriptorCompareInput(final RefactoringDescriptorProxy descriptor, final int kind) {
90         Assert.isNotNull(descriptor);
91         fDescriptor= descriptor;
92         fKind= kind;
93         if (!fImageRegistered) {
94             CompareUI.registerImageDescriptor(TYPE_REFACTORING_DESCRIPTOR, RefactoringPluginImages.DESC_OBJS_REFACTORING);
95             fImageRegistered= true;
96         }
97     }
98
99     /**
100      * {@inheritDoc}
101      */

102     public void addCompareInputChangeListener(final ICompareInputChangeListener listener) {
103         // Do nothing
104
}
105
106     /**
107      * {@inheritDoc}
108      */

109     public void copy(final boolean leftToRight) {
110         // Do nothing
111
}
112
113     /**
114      * {@inheritDoc}
115      */

116     public ITypedElement getAncestor() {
117         return new RefactoringDescriptorElement();
118     }
119
120     /**
121      * Returns the refactoring descriptor.
122      *
123      * @return the refactoring descriptor
124      */

125     public RefactoringDescriptorProxy getDescriptor() {
126         return fDescriptor;
127     }
128
129     /**
130      * {@inheritDoc}
131      */

132     public Image getImage() {
133         return CompareUI.getImage(TYPE_REFACTORING_DESCRIPTOR);
134     }
135
136     /**
137      * {@inheritDoc}
138      */

139     public int getKind() {
140         return fKind;
141     }
142
143     /**
144      * {@inheritDoc}
145      */

146     public ITypedElement getLeft() {
147         return new RefactoringDescriptorElement();
148     }
149
150     /**
151      * {@inheritDoc}
152      */

153     public String JavaDoc getName() {
154         return fDescriptor.getDescription();
155     }
156
157     /**
158      * {@inheritDoc}
159      */

160     public ITypedElement getRight() {
161         return new RefactoringDescriptorElement();
162     }
163
164     /**
165      * {@inheritDoc}
166      */

167     public void removeCompareInputChangeListener(final ICompareInputChangeListener listener) {
168         // Do nothing
169
}
170 }
171
Popular Tags