1 23 24 package org.objectweb.fractal.gui.tree.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.Configuration; 30 import org.objectweb.fractal.gui.model.Interface; 31 import org.objectweb.fractal.gui.selection.model.Selection; 32 import org.objectweb.fractal.gui.selection.model.SelectionListener; 33 34 import javax.swing.tree.DefaultTreeSelectionModel ; 35 import javax.swing.tree.TreePath ; 36 37 43 44 public class BasicTreeSelectionModel extends DefaultTreeSelectionModel 45 implements SelectionListener, BindingController 46 { 47 48 54 55 public final static String CONFIGURATION_BINDING = "configuration"; 56 57 61 62 public final static String SELECTION_BINDING = "selection"; 63 64 67 68 private Configuration configuration; 69 70 73 74 private Selection selection; 75 76 79 80 public BasicTreeSelectionModel () { 81 setSelectionMode(SINGLE_TREE_SELECTION); 82 } 83 84 88 public String [] listFc () { 89 return new String [] { CONFIGURATION_BINDING, SELECTION_BINDING }; 90 } 91 92 public Object lookupFc (final String clientItfName) { 93 if (CONFIGURATION_BINDING.equals(clientItfName)) { 94 return configuration; 95 } else if (SELECTION_BINDING.equals(clientItfName)) { 96 return selection; 97 } 98 return null; 99 } 100 101 public void bindFc ( 102 final String clientItfName, 103 final Object serverItf) 104 { 105 if (CONFIGURATION_BINDING.equals(clientItfName)) { 106 configuration = (Configuration)serverItf; 107 } else if (SELECTION_BINDING.equals(clientItfName)) { 108 selection = (Selection)serverItf; 109 } 110 } 111 112 public void unbindFc (final String clientItfName) { 113 if (CONFIGURATION_BINDING.equals(clientItfName)) { 114 configuration = null; 115 } else if (SELECTION_BINDING.equals(clientItfName)) { 116 selection = null; 117 } 118 } 119 120 124 public void selectionChanged () { 125 if (selection == null) { 126 clearSelection(); 127 } else { 128 Object o = selection.getSelection(); 129 if (o instanceof Interface) { 130 o = ((Interface)o).getOwner(); 131 } 132 if (o == null) { 133 clearSelection(); 134 } else { 135 super.setSelectionPath(new TreePath (((Component)o).getPath())); 136 } 137 } 138 } 139 140 144 public void setSelectionPath (final TreePath path) { 145 super.setSelectionPath(path); 146 Component component = (Component)path.getLastPathComponent(); 147 if (configuration != null) { 148 configuration.setRootComponent(component); 149 } 150 selection.selectComponent(component); 151 } 152 } 153 | Popular Tags |