KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > core > refactoring > TextEditBasedChangeGroup


1 /*******************************************************************************
2  * Copyright (c) 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.core.refactoring;
12
13 import org.eclipse.text.edits.TextEdit;
14 import org.eclipse.text.edits.TextEditGroup;
15
16 import org.eclipse.core.runtime.Assert;
17
18 import org.eclipse.jface.text.IRegion;
19
20 /**
21  * This class is a wrapper around a {@link TextEditGroup TextEditGroup}
22  * adding support for marking a group as active and inactive.
23  * <p>
24  * Note: this class is not intended to be extended by clients.
25  * </p>
26  *
27  * @see TextEditGroup
28  *
29  * @since 3.2
30  */

31 public class TextEditBasedChangeGroup {
32
33     /** The associated change */
34     private TextEditBasedChange fChange;
35     private boolean fIsEnabled;
36     private TextEditGroup fTextEditGroup;
37
38     /**
39      * Creates new <code>TextEditBasedChangeGroup</code> for the given <code>
40      * TextEditBasedChange</code> and <code>TextEditGroup</code>.
41      *
42      * @param change the change owning this text edit change group
43      * @param group the underlying text edit group
44      */

45     public TextEditBasedChangeGroup(TextEditBasedChange change, TextEditGroup group) {
46         Assert.isNotNull(change);
47         Assert.isNotNull(group);
48         fChange= change;
49         fIsEnabled= true;
50         fTextEditGroup= group;
51     }
52     
53     /**
54      * Returns the text edit change this group belongs to.
55      *
56      * @return the text edit change this group belongs to
57      */

58     public TextEditBasedChange getTextEditChange() {
59         return fChange;
60     }
61     
62     /**
63      * Returns the groups's name by forwarding the method
64      * to the underlying text edit group.
65      *
66      * @return the group's name
67      */

68     public String JavaDoc getName() {
69         return fTextEditGroup.getName();
70     }
71     
72     /**
73      * Returns the region covered by the underlying
74      * text edit group.
75      *
76      * @return the region covered by the underlying
77      * text edit group
78      */

79     public IRegion getRegion() {
80         return fTextEditGroup.getRegion();
81     }
82     
83     /**
84      * Returns the underlying text edit group.
85      *
86      * @return the underlying text edit group
87      */

88     public TextEditGroup getTextEditGroup() {
89         return fTextEditGroup;
90     }
91     
92     /**
93      * Returns the text edits managed by the underlying
94      * text edit group.
95      *
96      * @return the text edits managed by the underlying
97      * text edit group
98      */

99     public TextEdit[] getTextEdits() {
100         return fTextEditGroup.getTextEdits();
101     }
102     
103     /**
104      * Returns whether the group is enabled or not.
105      *
106      * @return <code>true</code> if the group is marked as
107      * enabled; <code>false</code> otherwise
108      */

109     public boolean isEnabled() {
110         return fIsEnabled;
111     }
112     
113     /**
114      * Marks the group as enabled or disabled. If a group
115      * is marked as disabled the text edits managed by the
116      * underlying text edit group aren't executed when
117      * performing the text change that owns this group.
118      *
119      * @param enabled <code>true</code> to mark this group
120      * as enabled, <code>false</code> to mark it as disabled
121      */

122     public void setEnabled(boolean enabled) {
123         fIsEnabled= enabled;
124     }
125     
126     /**
127      * Returns the set of group categories.
128      *
129      * @return the group categories of this change group
130      */

131     public GroupCategorySet getGroupCategorySet() {
132         if (fTextEditGroup instanceof CategorizedTextEditGroup) {
133             return ((CategorizedTextEditGroup)fTextEditGroup).getGroupCategorySet();
134         }
135         return GroupCategorySet.NONE;
136     }
137 }
Popular Tags