KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 org.eclipse.core.runtime.CoreException;
14
15 import org.eclipse.jface.util.Assert;
16
17 import org.eclipse.ltk.core.refactoring.Change;
18 import org.eclipse.ltk.core.refactoring.CompositeChange;
19 import org.eclipse.ltk.core.refactoring.TextChange;
20 import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput;
21 import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
22
23 public class DefaultChangeElement extends ChangeElement {
24     
25     private Change fChange;
26     private ChangeElement[] fChildren;
27
28     /**
29      * Creates a new <code>ChangeElement</code> for the given
30      * change.
31      *
32      * @param parent the change element's parent or <code>null
33      * </code> if the change element doesn't have a parent
34      * @param change the actual change. Argument must not be
35      * <code>null</code>
36      */

37     public DefaultChangeElement(ChangeElement parent, Change change) {
38         super(parent);
39         fChange= change;
40         Assert.isNotNull(fChange);
41     }
42
43     /**
44      * Returns the underlying <code>IChange</code> object.
45      *
46      * @return the underlying change
47      */

48     public Change getChange() {
49         return fChange;
50     }
51     
52     public Object JavaDoc getModifiedElement() {
53         return fChange;
54     }
55     
56     public ChangePreviewViewerDescriptor getChangePreviewViewerDescriptor() throws CoreException {
57         return ChangePreviewViewerDescriptor.get(fChange);
58     }
59     
60     public void feedInput(IChangePreviewViewer viewer) throws CoreException {
61         viewer.setInput(new ChangePreviewViewerInput(fChange));
62     }
63     
64     /* non Java-doc
65      * @see ChangeElement#setActive
66      */

67     public void setEnabled(boolean enabled) {
68         fChange.setEnabled(enabled);
69     }
70     
71     public void setEnabledShallow(boolean enabled) {
72         fChange.setEnabledShallow(enabled);
73     }
74     
75     /* non Java-doc
76      * @see ChangeElement.getActive
77      */

78     public int getActive() {
79         if (fChange instanceof CompositeChange || fChange instanceof TextChange)
80             return getCompositeChangeActive();
81         else
82             return getDefaultChangeActive();
83     }
84     
85     /* non Java-doc
86      * @see ChangeElement.getChildren
87      */

88     public ChangeElement[] getChildren() {
89         return fChildren;
90     }
91     
92     /**
93      * Sets the children.
94      *
95      * @param children the children of this node. Must not be <code>null</code>
96      */

97     public void setChildren(ChangeElement[] children) {
98         Assert.isNotNull(children);
99         fChildren= children;
100     }
101
102     private int getDefaultChangeActive() {
103         int result= fChange.isEnabled() ? ACTIVE : INACTIVE;
104         if (fChildren != null) {
105             for (int i= 0; i < fChildren.length; i++) {
106                 result= ACTIVATION_TABLE[fChildren[i].getActive()][result];
107                 if (result == PARTLY_ACTIVE)
108                     break;
109             }
110         }
111         return result;
112     }
113     
114     private int getCompositeChangeActive() {
115         if (fChildren != null && fChildren.length > 0) {
116             int result= fChildren[0].getActive();
117             for (int i= 1; i < fChildren.length; i++) {
118                 result= ACTIVATION_TABLE[fChildren[i].getActive()][result];
119                 if (result == PARTLY_ACTIVE)
120                     break;
121             }
122             return result;
123         } else {
124             return ACTIVE;
125         }
126     }
127 }
128
129
Popular Tags