1 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 37 public DefaultChangeElement(ChangeElement parent, Change change) { 38 super(parent); 39 fChange= change; 40 Assert.isNotNull(fChange); 41 } 42 43 48 public Change getChange() { 49 return fChange; 50 } 51 52 public Object 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 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 78 public int getActive() { 79 if (fChange instanceof CompositeChange || fChange instanceof TextChange) 80 return getCompositeChangeActive(); 81 else 82 return getDefaultChangeActive(); 83 } 84 85 88 public ChangeElement[] getChildren() { 89 return fChildren; 90 } 91 92 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 |