Mercurial > projects > dwt-addons
comparison dwtx/core/commands/operations/AbstractOperation.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 46a6e0e6ccd4 |
children |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwtx.core.commands.operations.AbstractOperation; | 13 module dwtx.core.commands.operations.AbstractOperation; |
14 | 14 |
15 import tango.util.collection.ArraySeq; | |
16 import tango.util.collection.model.Seq; | |
17 | |
18 import dwtx.core.commands.ExecutionException; | 15 import dwtx.core.commands.ExecutionException; |
19 import dwtx.core.runtime.Assert; | 16 import dwtx.core.runtime.Assert; |
20 import dwtx.core.runtime.IAdaptable; | 17 import dwtx.core.runtime.IAdaptable; |
21 import dwtx.core.runtime.IProgressMonitor; | 18 import dwtx.core.runtime.IProgressMonitor; |
22 import dwtx.core.runtime.IStatus; | 19 import dwtx.core.runtime.IStatus; |
23 | 20 |
24 import dwtx.core.commands.operations.IUndoableOperation; | 21 import dwtx.core.commands.operations.IUndoableOperation; |
25 import dwtx.core.commands.operations.IUndoContext; | 22 import dwtx.core.commands.operations.IUndoContext; |
26 | 23 |
27 import dwt.dwthelper.utils; | 24 import dwt.dwthelper.utils; |
25 import dwtx.dwtxhelper.Collection; | |
28 static import tango.text.Text; | 26 static import tango.text.Text; |
29 alias tango.text.Text.Text!(char) StringBuffer; | 27 alias tango.text.Text.Text!(char) StringBuffer; |
30 | 28 |
31 /** | 29 /** |
32 * <p> | 30 * <p> |
41 * @see dwtx.core.commands.operations.IUndoableOperation | 39 * @see dwtx.core.commands.operations.IUndoableOperation |
42 * | 40 * |
43 * @since 3.1 | 41 * @since 3.1 |
44 */ | 42 */ |
45 public abstract class AbstractOperation : IUndoableOperation { | 43 public abstract class AbstractOperation : IUndoableOperation { |
46 Seq!(IUndoContext) contexts; | 44 List contexts; |
47 | 45 |
48 private String label = ""; //$NON-NLS-1$ | 46 private String label = ""; //$NON-NLS-1$ |
49 | 47 |
50 /** | 48 /** |
51 * Construct an operation that has the specified label. | 49 * Construct an operation that has the specified label. |
55 * <code>null</code>. | 53 * <code>null</code>. |
56 */ | 54 */ |
57 public this(String label) { | 55 public this(String label) { |
58 Assert.isNotNull(label); | 56 Assert.isNotNull(label); |
59 this.label = label; | 57 this.label = label; |
60 contexts = new ArraySeq!(IUndoContext); | 58 contexts = new ArrayList(); |
61 } | 59 } |
62 | 60 |
63 /* | 61 /* |
64 * (non-Javadoc) | 62 * (non-Javadoc) |
65 * | 63 * |
66 * @see dwtx.core.commands.operations.IUndoableOperation#addContext(dwtx.core.commands.operations.IUndoContext) | 64 * @see dwtx.core.commands.operations.IUndoableOperation#addContext(dwtx.core.commands.operations.IUndoContext) |
67 * | 65 * |
68 * <p> Subclasses may override this method. </p> | 66 * <p> Subclasses may override this method. </p> |
69 */ | 67 */ |
70 public void addContext(IUndoContext context) { | 68 public void addContext(IUndoContext context) { |
71 if (!contexts.contains(context)) { | 69 if (!contexts.contains(cast(Object)context)) { |
72 contexts.append(context); | 70 contexts.add(cast(Object)context); |
73 } | 71 } |
74 } | 72 } |
75 | 73 |
76 /* | 74 /* |
77 * (non-Javadoc) | 75 * (non-Javadoc) |
125 * dwtx.core.runtime.IAdaptable) | 123 * dwtx.core.runtime.IAdaptable) |
126 */ | 124 */ |
127 public abstract IStatus execute(IProgressMonitor monitor, IAdaptable info); | 125 public abstract IStatus execute(IProgressMonitor monitor, IAdaptable info); |
128 | 126 |
129 public final IUndoContext[] getContexts() { | 127 public final IUndoContext[] getContexts() { |
130 return contexts.toArray(); | 128 return arraycast!(IUndoContext)(contexts.toArray()); |
131 } | 129 } |
132 | 130 |
133 /* | 131 /* |
134 * (non-Javadoc) | 132 * (non-Javadoc) |
135 * | 133 * |
158 * @see dwtx.core.commands.operations.IUndoableOperation#hasContext(dwtx.core.commands.operations.IUndoContext) | 156 * @see dwtx.core.commands.operations.IUndoableOperation#hasContext(dwtx.core.commands.operations.IUndoContext) |
159 */ | 157 */ |
160 public final bool hasContext(IUndoContext context) { | 158 public final bool hasContext(IUndoContext context) { |
161 Assert.isNotNull(cast(Object)context); | 159 Assert.isNotNull(cast(Object)context); |
162 for (int i = 0; i < contexts.size(); i++) { | 160 for (int i = 0; i < contexts.size(); i++) { |
163 IUndoContext otherContext = contexts.get(i); | 161 IUndoContext otherContext = cast(IUndoContext)contexts.get(i); |
164 // have to check both ways because one context may be more general | 162 // have to check both ways because one context may be more general |
165 // in | 163 // in |
166 // its matching rules than another. | 164 // its matching rules than another. |
167 if (context.matches(otherContext) || otherContext.matches(context)) { | 165 if (context.matches(otherContext) || otherContext.matches(context)) { |
168 return true; | 166 return true; |
186 * <p> Default implementation. Subclasses may override this method. | 184 * <p> Default implementation. Subclasses may override this method. |
187 * </p> | 185 * </p> |
188 */ | 186 */ |
189 | 187 |
190 public void removeContext(IUndoContext context) { | 188 public void removeContext(IUndoContext context) { |
191 contexts.remove(context); | 189 contexts.remove(cast(Object)context); |
192 } | 190 } |
193 | 191 |
194 /* | 192 /* |
195 * (non-Javadoc) | 193 * (non-Javadoc) |
196 * | 194 * |