1 23 24 package org.objectweb.fractal.gui.selection.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.model.Component; 29 import org.objectweb.fractal.gui.model.Interface; 30 31 import java.util.Map ; 32 import java.util.HashMap ; 33 import java.util.Iterator ; 34 35 38 39 public class BasicSelection implements Selection, BindingController { 40 41 45 46 public final static String SELECTION_LISTENERS_BINDING = 47 "selection-listeners"; 48 49 52 53 private Map selectionListeners; 54 55 58 59 private Component selectedComponent; 60 61 64 65 private Interface selectedInterface; 66 67 70 71 public BasicSelection () { 72 selectionListeners = new HashMap (); 73 } 74 75 79 public String [] listFc () { 80 return (String [])selectionListeners.keySet().toArray( 81 new String [selectionListeners.size()]); 82 } 83 84 public Object lookupFc (final String clientItfName) { 85 if (clientItfName.startsWith(SELECTION_LISTENERS_BINDING)) { 86 return selectionListeners.get(clientItfName); 87 } 88 return null; 89 } 90 91 92 public void bindFc ( 93 final String clientItfName, 94 final Object serverItf) 95 { 96 if (clientItfName.startsWith(SELECTION_LISTENERS_BINDING)) { 97 selectionListeners.put(clientItfName, serverItf); 98 } 99 } 100 101 102 public void unbindFc (final String clientItfName) { 103 if (clientItfName.startsWith(SELECTION_LISTENERS_BINDING)) { 104 selectionListeners.remove(clientItfName); 105 } 106 } 107 108 112 public Object getSelection () { 113 if (selectedInterface == null) { 114 return selectedComponent; 115 } else { 116 return selectedInterface; 117 } 118 } 119 120 public void selectComponent (final Component component) { 121 if (selectedComponent != component) { 122 selectedComponent = component; 123 selectedInterface = null; 124 notifyListeners(); 125 } 126 } 127 128 public void selectInterface (final Interface itf) { 129 if (selectedInterface != itf) { 130 selectedComponent = null; 131 selectedInterface = itf; 132 notifyListeners(); 133 } 134 } 135 136 public void clearSelection () { 137 if (getSelection() != null) { 138 selectedComponent = null; 139 selectedInterface = null; 140 notifyListeners(); 141 } 142 } 143 144 148 151 152 private void notifyListeners () { 153 Iterator i = selectionListeners.values().iterator(); 154 while (i.hasNext()) { 155 ((SelectionListener)i.next()).selectionChanged(); 156 } 157 } 158 } 159 | Popular Tags |