001/* 002 * Copyright (c) 2003-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.ecoinformatics.seek.ecogrid; 031 032import java.awt.BorderLayout; 033import java.awt.Dimension; 034import java.awt.event.ItemEvent; 035import java.awt.event.ItemListener; 036import java.util.Hashtable; 037import java.util.Vector; 038 039import javax.swing.Box; 040import javax.swing.BoxLayout; 041import javax.swing.JButton; 042import javax.swing.JComboBox; 043import javax.swing.JDialog; 044import javax.swing.JLabel; 045import javax.swing.JPanel; 046import javax.swing.JTextField; 047 048import org.apache.commons.logging.Log; 049import org.apache.commons.logging.LogFactory; 050 051/** 052 * This class represents a dialog box for searching registry 053 * 054 * @author Jing Tao 055 */ 056 057public class RegistrySearchDialog extends JDialog { 058 private static final int WIDTH = 500; 059 private static final int HEIGHT = 200; 060 private static final String CONTAINS = "contains"; 061 062 private JPanel mainPanel = new JPanel(); 063 private JButton searchButton = null; 064 private JButton cancelButton = null; 065 private JComboBox optionList = null; 066 private JTextField inputField = new JTextField(); 067 private Vector options = new Vector(); 068 private EcogridPreferencesTab parent = null; 069 private Hashtable xpathMap = new Hashtable(); 070 private Vector originalServiceList = null; 071 072 public static final String SERVICENAME = "Service Name"; 073 public static final String LOCATION = "Location"; 074 public static final String ALLSERVICES = "All Services"; 075 public static final String SERVICENAMEXPATH = "serviceName"; 076 public static final String LOCATIONXPATH = "endPoint"; 077 078 protected final static Log log; 079 static { 080 log = LogFactory 081 .getLog("org.ecoinformatics.seek.ecogrid.GetMetadataAction"); 082 } 083 084 /** 085 * Construct of this dialog 086 * 087 * @param parent 088 * Frame 089 * @param title 090 * String 091 */ 092 public RegistrySearchDialog(EcogridPreferencesTab parent, String title, 093 Vector originalServiceList) { 094 this.parent = parent; 095 this.originalServiceList = originalServiceList; 096 this.setLocation(parent.getLocation()); 097 setSize(new Dimension(WIDTH, HEIGHT)); 098 initMainPanel(); 099 getContentPane().add( 100 Box.createVerticalStrut(EcogridPreferencesTab.MARGINGSIZE), 101 BorderLayout.NORTH); 102 getContentPane().add( 103 Box.createHorizontalStrut(EcogridPreferencesTab.MARGINGSIZE), 104 BorderLayout.EAST); 105 getContentPane().add(mainPanel, BorderLayout.CENTER); 106 getContentPane().add( 107 Box.createVerticalStrut(EcogridPreferencesTab.MARGINGSIZE), 108 BorderLayout.SOUTH); 109 getContentPane().add( 110 Box.createHorizontalStrut(EcogridPreferencesTab.MARGINGSIZE), 111 BorderLayout.WEST); 112 setVisible(true); 113 }// RegistrySearchDialog 114 115 /* 116 * Method to init panels 117 */ 118 private void initMainPanel() { 119 JPanel selectionPanel = new JPanel(); 120 selectionPanel 121 .setLayout(new BoxLayout(selectionPanel, BoxLayout.X_AXIS)); 122 initOptions(); 123 optionList = new JComboBox(options); 124 optionList.setEditable(false); 125 optionList.addItemListener(new TextFieldEnableController()); 126 selectionPanel.add(optionList); 127 selectionPanel.add(Box.createHorizontalStrut(EcogridPreferencesTab.GAP)); 128 JLabel label = new JLabel(CONTAINS); 129 selectionPanel.add(label); 130 selectionPanel.add(Box.createHorizontalStrut(EcogridPreferencesTab.GAP)); 131 inputField.setEnabled(false); 132 selectionPanel.add(inputField); 133 selectionPanel.add(Box.createHorizontalGlue()); 134 135 mainPanel.setLayout(new BorderLayout()); 136 mainPanel.add(selectionPanel, BorderLayout.NORTH); 137 mainPanel.add(Box.createVerticalGlue(), BorderLayout.CENTER); 138 139 JPanel buttonPanel = new JPanel(); 140 JPanel rightButtonPanel = new JPanel(); 141 rightButtonPanel.setLayout(new BoxLayout(rightButtonPanel, 142 BoxLayout.X_AXIS)); 143 /*searchButton = new JButton(new SearchRegistryAction("Search", this, 144 parent, parent.getLocation())); 145 searchButton.setPreferredSize(ServicesDisplayFrame.BUTTONDIMENSION); 146 searchButton.setMaximumSize(ServicesDisplayFrame.BUTTONDIMENSION); 147 rightButtonPanel.add(searchButton);*/ 148 rightButtonPanel.add(Box 149 .createHorizontalStrut(EcogridPreferencesTab.MARGINGSIZE)); 150 cancelButton = new JButton(new CancelSearchAction("Cancel", this, 151 parent)); 152 cancelButton.setPreferredSize(EcogridPreferencesTab.BUTTONDIMENSION); 153 cancelButton.setMaximumSize(EcogridPreferencesTab.BUTTONDIMENSION); 154 rightButtonPanel.add(cancelButton); 155 buttonPanel.setLayout(new BorderLayout()); 156 buttonPanel.add(Box.createHorizontalGlue(), BorderLayout.CENTER); 157 buttonPanel.add(rightButtonPanel, BorderLayout.EAST); 158 159 mainPanel.add(buttonPanel, BorderLayout.SOUTH); 160 }// initMainPanel 161 162 /* 163 * Method to initialize option list 164 */ 165 private void initOptions() { 166 options.add(ALLSERVICES); 167 options.add(SERVICENAME); 168 options.add(LOCATION); 169 xpathMap.put(SERVICENAME, SERVICENAMEXPATH); 170 xpathMap.put(LOCATION, LOCATIONXPATH); 171 }// initOptions 172 173 /** 174 * Method to get the selected xpath in combobox. 175 * 176 * @return String 177 */ 178 public String getXPath() { 179 Object selectedObj = optionList.getSelectedItem(); 180 String selectedString = (String) selectedObj; 181 log.debug("The selcted xpath is " + selectedString); 182 return selectedString; 183 }// getXPath 184 185 /** 186 * Get the value from input text field 187 * 188 * @return String 189 */ 190 public String getSearchValue() { 191 String value = inputField.getText(); 192 log.debug("The input value is " + value); 193 return value; 194 }// getValue 195 196 /** 197 * This method will retrun a xpath for optionLabel. For example, optionLabel 198 * is "Location" and xpath is "endPoint". 199 * 200 * @param optionLabel 201 * String 202 * @return String 203 */ 204 public String getXPath(String optionLabel) { 205 String xpath = null; 206 xpath = (String) xpathMap.get(optionLabel); 207 return xpath; 208 }// getXPath 209 210 /* 211 * When option list selected is all service, the text field should be 212 * disable(Because no value needed). If option is not at all service the 213 * text box should be enable 214 */ 215 private class TextFieldEnableController implements ItemListener { 216 217 public void itemStateChanged(ItemEvent e) { 218 if (e.getStateChange() == ItemEvent.SELECTED) { 219 // clear text in text box 220 inputField.setText(""); 221 String selectedString = (String) optionList.getSelectedItem(); 222 log.debug("Selected item is " + selectedString); 223 if (selectedString != null 224 && !selectedString.equals(ALLSERVICES)) { 225 inputField.setEnabled(true); 226 }// if 227 else { 228 inputField.setEnabled(false); 229 }// else 230 }// if 231 }// itemStateChanged 232 }// TextFieldEnableController 233 234 public static void main(String[] arg) { 235 // Frame parent = new Frame("hello"); 236 // RegistrySearchDialog dialog = new RegistrySearchDialog(null, 237 // "RegistrySearch"); 238 } 239 240}// RegistrySearchDialog