1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.util.List ; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 18 import org.eclipse.ltk.core.refactoring.GroupCategorySet; 19 import org.eclipse.ltk.core.refactoring.TextEditBasedChange; 20 import org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup; 21 import org.eclipse.ltk.core.refactoring.Change; 22 23 import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; 24 import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; 25 import org.eclipse.ltk.ui.refactoring.TextEditChangeNode; 26 27 import org.eclipse.jface.resource.ImageDescriptor; 28 import org.eclipse.jface.text.IRegion; 29 30 public final class TextEditGroupNode extends TextEditChangeNode.ChildNode { 31 32 private TextEditBasedChangeGroup fChangeGroup; 33 34 public TextEditGroupNode(PreviewNode parent, TextEditBasedChangeGroup changeGroup) { 35 super(parent); 36 fChangeGroup= changeGroup; 37 Assert.isNotNull(fChangeGroup); 38 } 39 40 45 TextEditBasedChangeGroup getChangeGroup() { 46 return fChangeGroup; 47 } 48 49 public String getText() { 50 return fChangeGroup.getName(); 51 } 52 53 public ImageDescriptor getImageDescriptor() { 54 return RefactoringPluginImages.DESC_OBJS_TEXT_EDIT; 55 } 56 57 ChangePreviewViewerDescriptor getChangePreviewViewerDescriptor() throws CoreException { 58 InternalTextEditChangeNode element= getTextEditChangeNode(); 59 if (element == null) 60 return null; 61 return element.getChangePreviewViewerDescriptor(); 62 } 63 64 void feedInput(IChangePreviewViewer viewer, List categories) throws CoreException { 65 InternalTextEditChangeNode element= getTextEditChangeNode(); 66 if (element != null) { 67 Change change= element.getChange(); 68 if (change instanceof TextEditBasedChange) { 69 IRegion range= getTextRange(this); 70 ChangePreviewViewerInput input= null; 71 if (range != null) { 72 input= TextEditChangePreviewViewer.createInput(change, new TextEditBasedChangeGroup[] {fChangeGroup}, range); 73 } else { 74 input= TextEditChangePreviewViewer.createInput(change, fChangeGroup, 2); 75 } 76 viewer.setInput(input); 77 } 78 } else { 79 viewer.setInput(null); 80 } 81 } 82 83 void setEnabled(boolean enabled) { 84 fChangeGroup.setEnabled(enabled); 85 } 86 87 void setEnabledShallow(boolean enabled) { 88 fChangeGroup.setEnabled(enabled); 89 } 90 91 int getActive() { 92 return fChangeGroup.isEnabled() ? PreviewNode.ACTIVE : PreviewNode.INACTIVE; 93 } 94 95 PreviewNode[] getChildren() { 96 return PreviewNode.EMPTY_CHILDREN; 97 } 98 99 boolean hasOneGroupCategory(List categories) { 100 return fChangeGroup.getGroupCategorySet().containsOneCategory(categories); 101 } 102 103 boolean hasDerived() { 104 return false; 105 } 106 107 GroupCategorySet getGroupCategorySet() { 108 return fChangeGroup.getGroupCategorySet(); 109 } 110 111 private static IRegion getTextRange(PreviewNode element) throws CoreException { 112 if (element == null) 113 return null; 114 if (element instanceof InternalLanguageElementNode) { 115 return ((InternalLanguageElementNode)element).getTextRange(); 116 } else if (element instanceof TextEditChangeNode) { 117 return null; 118 } 119 return getTextRange(element.getParent()); 120 } 121 } 122 | Popular Tags |