1 19 package org.openharmonise.him.metadata.range.swing.domain; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Container ; 25 import java.awt.Dimension ; 26 import java.awt.LayoutManager ; 27 import java.awt.event.MouseEvent ; 28 import java.awt.event.MouseListener ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 import javax.swing.BorderFactory ; 33 import javax.swing.JPanel ; 34 import javax.swing.JScrollPane ; 35 36 import org.openharmonise.him.harmonise.*; 37 import org.openharmonise.him.window.messages.*; 38 import org.openharmonise.vfs.metadata.value.*; 39 40 41 46 public class DomainSelectionList 47 extends JPanel 48 implements MouseListener , LayoutManager { 49 50 private JPanel m_listPanel = null; 51 52 private DomainRangeDisplay m_display = null; 53 54 private boolean m_bListenToCombo = true; 55 56 59 public DomainSelectionList(DomainRangeDisplay display) { 60 super(); 61 this.m_display = display; 62 this.setup(); 63 } 64 65 private void setup() { 66 this.setBackground(Color.WHITE); 67 this.setLayout(new BorderLayout ()); 68 69 this.m_listPanel = new JPanel (); 70 this.m_listPanel.setLayout(this); 71 this.m_listPanel.setBackground(Color.WHITE); 72 73 this.m_listPanel.add( new DomainSelectionHeader() ); 74 75 JScrollPane scroller = new JScrollPane (this.m_listPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 76 scroller.setBorder(BorderFactory.createEmptyBorder()); 77 this.add(scroller); 78 79 } 80 81 protected void setListenToCombo(boolean bListenToCombo) { 82 this.m_bListenToCombo = bListenToCombo; 83 } 84 85 public void addDomain(DomainValue value) { 86 boolean bFound = false; 87 for(int i=0; i<this.m_listPanel.getComponentCount(); i++) { 88 Component comp = this.m_listPanel.getComponent(i); 89 if(comp instanceof DomainSelectionCell && ((DomainSelectionCell)comp).getPath().equals(value.getPath()) ) { 90 if(this.m_bListenToCombo==false) { 91 ((DomainSelectionCell)comp).setListenToCombo(false); 92 } 93 ((DomainSelectionCell)comp).setType(DomainSelectionCell.TYPE_BOTH); 94 if(this.m_bListenToCombo==false) { 95 ((DomainSelectionCell)comp).setListenToCombo(true); 96 } 97 bFound=true; 98 } 99 } 100 if(!bFound) { 101 try { 102 DomainSelectionCell cell = new DomainSelectionCell(this, value); 103 if( this.m_display.getPropertyInstance().getVirtualFile().getFullPath().startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS) ) { 104 cell.setOccursSpinnersEnabled(false); 105 } 106 this.m_listPanel.add( cell ); 107 this.m_listPanel.setPreferredSize(new Dimension (300, 20*this.m_listPanel.getComponentCount()) ); 108 } catch(Exception e) { 109 e.printStackTrace(); 110 MessageHandler.getInstance().fireMessageEvent("One of the Domains contains a reference to a Collection that cannot be found on the server [" + value.getPath() + "]. This domain has been removed.", MessageHandler.TYPE_ERROR); 111 } 112 } 113 this.validateTree(); 114 } 115 116 public void removeSelectedCell() { 117 DomainSelectionCell cell = this.getSelectedCell(); 118 if(cell!=null) { 119 this.m_listPanel.remove(cell); 120 } 121 } 122 123 private DomainSelectionCell getSelectedCell() { 124 DomainSelectionCell cell = null; 125 for(int i=0; i<this.m_listPanel.getComponentCount(); i++) { 126 Component comp = this.m_listPanel.getComponent(i); 127 if(comp instanceof DomainSelectionCell && ((DomainSelectionCell)comp).isSelected() ) { 128 cell = (DomainSelectionCell) comp; 129 } 130 } 131 return cell; 132 } 133 134 public void cellSelected(DomainSelectionCell cell) { 135 for(int i=0; i<this.m_listPanel.getComponentCount(); i++) { 136 Component comp = this.m_listPanel.getComponent(i); 137 if(comp instanceof DomainSelectionCell) { 138 ((DomainSelectionCell)comp).setCellSelected(false); 139 } 140 } 141 cell.setCellSelected(true); 142 this.validateTree(); 143 this.repaint(); 144 } 145 146 protected DomainValue getNewValueInstance() { 147 return this.m_display.getNewValueInstance(); 148 } 149 150 protected void domainValuesChanged() { 151 this.m_display.domainValuesChanged(); 152 } 153 154 protected List getValues() { 155 ArrayList aValues = new ArrayList (); 156 157 for(int i=0; i<this.m_listPanel.getComponentCount(); i++) { 158 Component comp = this.m_listPanel.getComponent(i); 159 if(comp instanceof DomainSelectionCell) { 160 aValues.addAll( ((DomainSelectionCell)comp).getValues() ); 161 } 162 } 163 164 return aValues; 165 } 166 167 170 public void mouseClicked(MouseEvent arg0) { 171 172 } 173 174 177 public void layoutContainer(Container arg0) { 178 179 for(int i=0; i<this.m_listPanel.getComponentCount(); i++) { 180 Component comp = this.m_listPanel.getComponent(i); 181 comp.setSize(comp.getPreferredSize()); 182 comp.setLocation(0, i*20); 183 } 184 } 185 186 189 public Dimension getPreferredSize() { 190 return new Dimension (320,250); 191 } 192 193 196 public void mouseEntered(MouseEvent arg0) { 197 } 198 199 202 public void mouseExited(MouseEvent arg0) { 203 } 204 205 208 public void mousePressed(MouseEvent arg0) { 209 } 210 211 214 public void mouseReleased(MouseEvent arg0) { 215 } 216 217 220 public void removeLayoutComponent(Component arg0) { 221 } 222 223 226 public void addLayoutComponent(String arg0, Component arg1) { 227 } 228 229 232 public Dimension minimumLayoutSize(Container arg0) { 233 return this.getPreferredSize(); 234 } 235 236 239 public Dimension preferredLayoutSize(Container arg0) { 240 return this.getPreferredSize(); 241 } 242 243 246 private DomainSelectionList(boolean arg0) { 247 super(arg0); 248 } 249 250 253 private DomainSelectionList(LayoutManager arg0) { 254 super(arg0); 255 } 256 257 261 private DomainSelectionList(LayoutManager arg0, boolean arg1) { 262 super(arg0, arg1); 263 } 264 265 } 266 | Popular Tags |