KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > PreviewNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 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;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.CoreException;
17
18
19
20 import org.eclipse.jface.resource.ImageDescriptor;
21
22 import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
23
24 /**
25  * Instances of <code>PreviewNode</code> are used to present <code>
26  * IChange</code> object as nodes in a tree.
27  */

28 public abstract class PreviewNode {
29     
30     /** Flag indicating that the change element isn't active */
31     final static int INACTIVE= 0;
32     
33     /** Flag indicating that the change element is partly active (some children are inactive) */
34     final static int PARTLY_ACTIVE= 1;
35     
36     /** Flage indicating that the change element is active */
37     final static int ACTIVE= 2;
38     
39     final static int[][] ACTIVATION_TABLE= new int[][] {
40                                 /*INACTIVE*/ /*PARTLY_ACTIVE */ /*ACTIVE */
41         /* INACTIVE */ { INACTIVE, PARTLY_ACTIVE, PARTLY_ACTIVE },
42         /* PARTLY_ACTIVE*/ { PARTLY_ACTIVE, PARTLY_ACTIVE, PARTLY_ACTIVE },
43         /* ACTIVE */ { PARTLY_ACTIVE, PARTLY_ACTIVE, ACTIVE}
44     };
45     
46     static final PreviewNode[] EMPTY_CHILDREN= new PreviewNode[0];
47     
48     private PreviewNode fParent;
49
50     /**
51      * Creates a new <code>PreviewNode</code> with the
52      * given parent
53      *
54      * @param parent the change element's parent or <code>null
55      * </code> if the change element doesn't have a parent
56      */

57     protected PreviewNode(PreviewNode parent) {
58         fParent= parent;
59     }
60     
61     /**
62      * Initializes the change node with the given parent. This method
63      * should only be used if the change node has been created via
64      * getAdapter and the parent must be set after creation.
65      *
66      * @param parent the parent or <code>null</code>
67      */

68     /* package */ void initialize(PreviewNode parent) {
69         Assert.isTrue(fParent == null);
70         fParent= parent;
71     }
72
73     /**
74      * Returns the change element's parent.
75      *
76      * @return the change element's parent
77      */

78     PreviewNode getParent() {
79         return fParent;
80     }
81     
82     /**
83      * Returns the text used to render this node in the
84      * UI.
85      *
86      * @return a human readable representation of this node
87      */

88     public abstract String JavaDoc getText();
89     
90     /**
91      * Returns the image descriptor used to render this node
92      * in the UI.
93      *
94      * @return the image descriptor representing this node
95      */

96     public abstract ImageDescriptor getImageDescriptor();
97     
98     /**
99      * Returns the viewer descriptor used to present a preview of this change element
100      *
101      * @return the viewer suitable to present a preview of this change or
102      * <code>null</code> if no previewer is configured.
103      *
104      * @throws CoreException if an error occurred while creating the descriptor
105      */

106     abstract ChangePreviewViewerDescriptor getChangePreviewViewerDescriptor() throws CoreException;
107     
108     /**
109      * Feeds the input that corresponds to this change element into the
110      * given viewer.
111      *
112      * @param viewer the viewer to feed the input into
113      * @param categories the group categories to filter for or
114      * <code>null</code> if no filtering should take place
115      *
116      * @throws CoreException if an error occurred while feeding the input
117      */

118     abstract void feedInput(IChangePreviewViewer viewer, List JavaDoc/*<GroupCategory>*/ categories) throws CoreException;
119     
120     /**
121      * Sets the activation status for this <code>PreviewNode</code>. When a
122      * change element is not active, then executing it is expected to do nothing.
123      *
124      * @param enabled the activation status for this change element
125      */

126     abstract void setEnabled(boolean enabled);
127     
128     /**
129      * Sets the activation status for this <code>PreviewNode</code>. When a
130      * change element is not active, then executing it is expected to do nothing.
131      *
132      * @param enabled the activation status for this change element
133      */

134     abstract void setEnabledShallow(boolean enabled);
135     
136     /**
137      * Returns the activation status of this <code>PreviewNode</code>.
138      * Returns one of the following values: <code>IChange.ACTIVE</code>
139      * if the node and all its children are active, <code>IChange.INACTIVE</code>
140      * if all children and the node itself is inactive, and <code>IChange.PARTLY_ACTIVE
141      * </code>otherwise.
142      *
143      * @return the change element's activation status.
144      */

145     abstract int getActive();
146     
147     /**
148      * Returns the change element's children.
149      *
150      * @return the change element's children.
151      */

152     abstract PreviewNode[] getChildren();
153     
154     /**
155      * Returns <code>true</code> if the change node has
156      * one of the given group categories. Otherwise,
157      * <code>false</code> is returned.
158      *
159      * @param categories the group categories to check
160      *
161      * @return whether the change node has one of the given
162      * group categories
163      */

164     abstract boolean hasOneGroupCategory(List JavaDoc/*<GroupCategory>*/ categories);
165     
166     /**
167      * Returns <code>true</code> if the change node contains
168      * at least one derived resource. Otherwise, <code>false</code> is returned.
169      *
170      * @return whether the change node contains a derived resource
171      */

172     abstract boolean hasDerived();
173 }
174
Popular Tags