diff dwtx/jface/action/ExternalActionManager.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 7ffeace6c47f
children
line wrap: on
line diff
--- a/dwtx/jface/action/ExternalActionManager.d	Sun Aug 03 17:01:51 2008 +0200
+++ b/dwtx/jface/action/ExternalActionManager.d	Thu Aug 07 15:01:33 2008 +0200
@@ -15,10 +15,6 @@
 
 import dwtx.jface.action.IAction;
 
-import tango.util.collection.HashMap;
-import tango.util.collection.HashSet;
-import tango.util.collection.model.Map;
-import tango.util.collection.model.Set;
 
 import dwt.widgets.Event;
 import dwtx.core.commands.Command;
@@ -47,6 +43,7 @@
 import dwtx.jface.util.Util;
 
 import dwt.dwthelper.utils;
+import dwtx.dwtxhelper.Collection;
 import dwt.dwthelper.ResourceBundle;
 import tango.text.convert.Format;
 
@@ -73,11 +70,6 @@
  */
 public final class ExternalActionManager {
 
-    private static HashMap!(String,String) EMPTY_MAP;
-    static this(){
-        EMPTY_MAP = new HashMap!(String,String);
-    }
-
     /**
      * A simple implementation of the <code>ICallback</code> mechanism that
      * simply takes a <code>BindingManager</code> and a
@@ -130,7 +122,7 @@
          * will be removed from this set and the listener removed. This value
          * may be empty, but never <code>null</code>.
          */
-        private const Set!(String) loggedCommandIds;
+        private const Set loggedCommandIds;
 
         /**
          * The list of listeners that have registered for property change
@@ -138,7 +130,7 @@
          * to listeners (<code>IPropertyChangeListener</code> or
          * <code>ListenerList</code> of <code>IPropertyChangeListener</code>).
          */
-        private const Map!(String,IPropertyChangeListener) registeredListeners;
+        private const Map registeredListeners;
 
         static this(){
             RESOURCE_BUNDLE = ResourceBundle.getBundle(
@@ -219,8 +211,8 @@
                 CommandManager commandManager,
                 IActiveChecker activeChecker,
                 IExecuteApplicable checker) {
-            loggedCommandIds = new HashSet!(String);
-            registeredListeners = new HashMap!(String,IPropertyChangeListener);
+            loggedCommandIds = new HashSet();
+            registeredListeners = new HashMap();
             if (bindingManager is null) {
                 throw new NullPointerException(
                         "The callback needs a binding manager"); //$NON-NLS-1$
@@ -260,7 +252,7 @@
                 listeners.add(existing);
                 listeners.add(cast(Object)listener);
             } else {
-                registeredListeners.add(commandId, listener);
+                registeredListeners.put(commandId, cast(Object)listener);
             }
             if (!bindingManagerListenerAttached) {
                 bindingManager.addBindingManagerListener(this);
@@ -270,17 +262,17 @@
 
         public final void bindingManagerChanged(BindingManagerEvent event) {
             if (event.isActiveBindingsChanged()) {
-                foreach( k,v; registeredListeners ){
-//                 Iterator listenerItr = registeredListeners.entrySet()
-//                         .iterator();
-//                 while (listenerItr.hasNext()) {
-//                     Map.Entry entry = cast(Map.Entry) listenerItr.next();
-                    String commandId = k;//stringcast(k);// entry.getKey();
-                    Command command = commandManager.getCommand(commandId);
+                final Iterator listenerItr = registeredListeners.entrySet()
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    Map.Entry entry = cast(Map.Entry) listenerItr.next();
+                    String commandId = stringcast( entry.getKey());
+                    Command command = commandManager
+                            .getCommand(commandId);
                     ParameterizedCommand parameterizedCommand = new ParameterizedCommand(
                             command, null);
                     if (event.isActiveBindingsChangedFor(parameterizedCommand)) {
-                        Object value = cast(Object) v;
+                        Object value = entry.getValue();
                         PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(event
                                 .getManager(), IAction.TEXT, null, null);
                         if (null !is cast(ListenerList)value ) {
@@ -301,7 +293,7 @@
         /**
          * @see dwtx.jface.action.ExternalActionManager.ICallback#getAccelerator(String)
          */
-        public ValueWrapperInt getAccelerator(String commandId) {
+        public Integer getAccelerator(String commandId) {
             TriggerSequence triggerSequence = bindingManager
                     .getBestActiveBindingFor(commandId);
             if (triggerSequence !is null) {
@@ -311,7 +303,7 @@
                     if ( auto keyStroke = cast(KeyStroke) trigger ) {
                         int accelerator = SWTKeySupport
                                 .convertKeyStrokeToAccelerator(keyStroke);
-                        return new ValueWrapperInt(accelerator);
+                        return new Integer(accelerator);
                     }
                 }
             }
@@ -422,8 +414,8 @@
                 IPropertyChangeListener listener) {
             Object existing = cast(Object) registeredListeners.get(commandId);
             if (existing is cast(Object)listener) {
-                registeredListeners.removeKey(commandId);
-                if (registeredListeners.drained()) {
+                registeredListeners.remove(commandId);
+                if (registeredListeners.isEmpty()) {
                     bindingManager.removeBindingManagerListener(this);
                     bindingManagerListenerAttached = false;
                 }
@@ -431,7 +423,7 @@
                 ListenerList existingList = cast(ListenerList) existing;
                 existingList.remove(cast(Object)listener);
                 if (existingList.size() is 1) {
-                    registeredListeners.add(commandId, cast(IPropertyChangeListener)existingList.getListeners()[0]);
+                    registeredListeners.put(commandId, existingList.getListeners()[0]);
                 }
             }
         }
@@ -447,7 +439,7 @@
             }
             Command command = commandManager.getCommand(actionDefinitionId);
             ExecutionEvent executionEvent = new ExecutionEvent(command,
-                    EMPTY_MAP, event, null);
+                    Collections.EMPTY_MAP, event, null);
 
             commandManager.firePreExecute(actionDefinitionId, executionEvent);
         }