KickJava   Java API By Example, From Geeks To Geeks.

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


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 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     /**
41      * Returns the <code>TextEditBasedChangeGroup</code> managed by this node.
42      *
43      * @return the <code>TextEditBasedChangeGroup</code>
44      */

45     TextEditBasedChangeGroup getChangeGroup() {
46         return fChangeGroup;
47     }
48     
49     public String JavaDoc 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 JavaDoc 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 JavaDoc 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