1 23 24 package org.objectweb.fractal.gui.dialog.model; 25 26 import org.objectweb.fractal.gui.model.ClientInterface; 27 import org.objectweb.fractal.gui.model.Component; 28 import org.objectweb.fractal.gui.model.Interface; 29 import org.objectweb.fractal.gui.model.ServerInterface; 30 import org.objectweb.fractal.gui.selection.model.Selection; 31 32 import javax.swing.DefaultListSelectionModel ; 33 34 41 42 public class InterfaceTableSelectionModel extends DefaultListSelectionModel { 43 44 47 48 private boolean isClient; 49 50 53 54 private Component model; 55 56 59 60 private Selection selection; 61 62 67 68 InterfaceTableSelectionModel (final boolean isClient) { 69 this.isClient = isClient; 70 setSelectionMode(SINGLE_SELECTION); 71 } 72 73 78 79 void setComponentModel (final Component model) { 80 this.model = model; 81 } 82 83 88 89 void setSelection (final Selection selection) { 90 this.selection = selection; 91 } 92 93 97 98 void selectionChanged () { 99 int index = -1; 100 Object o = selection.getSelection(); 101 if (o instanceof Interface) { 102 Interface i = (Interface)o; 103 if (i.isInternal()) { 104 i = i.getComplementaryInterface(); 105 } 106 if (i instanceof ClientInterface && isClient) { 107 index = i.getOwner().getClientInterfaces().indexOf(i); 108 } else if (i instanceof ServerInterface && !isClient) { 109 index = i.getOwner().getServerInterfaces().indexOf(i); 110 } 111 } 112 if (index == -1) { 113 clearSelection(); 114 } else { 115 super.setSelectionInterval(index, index); 116 } 117 } 118 119 123 public void setSelectionInterval (final int index0, final int index1) { 124 super.setSelectionInterval(index0, index1); 125 if (model != null && selection != null) { 126 Interface i = null; 127 try { 128 if (isClient) { 129 i = (Interface)model.getClientInterfaces().get(index0); 130 } else { 131 i = (Interface)model.getServerInterfaces().get(index0); 132 } 133 } catch (Exception e) { 134 } 135 if (i != null) { 136 selection.selectInterface(i); 137 } 138 } 139 } 140 } 141 | Popular Tags |