1 4 package com.tc.installer.panel; 5 6 import com.tc.installer.util.WarFileFilter; 7 import com.zerog.ia.api.pub.CustomCodePanel; 8 import com.zerog.ia.api.pub.CustomCodePanelProxy; 9 10 import java.awt.Color ; 11 import java.awt.GridBagConstraints ; 12 import java.awt.GridBagLayout ; 13 import java.awt.Insets ; 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.ActionListener ; 16 import java.io.File ; 17 import java.io.FileFilter ; 18 import java.util.ArrayList ; 19 20 import javax.swing.BorderFactory ; 21 import javax.swing.ButtonGroup ; 22 import javax.swing.JButton ; 23 import javax.swing.JFileChooser ; 24 import javax.swing.JFrame ; 25 import javax.swing.JList ; 26 import javax.swing.JPanel ; 27 import javax.swing.JRadioButton ; 28 import javax.swing.JScrollPane ; 29 import javax.swing.JTextField ; 30 import javax.swing.JTextPane ; 31 32 public class ChooseWarFiles extends CustomCodePanel { 33 34 private static final String MESSAGE_TEXT_NO = "I do not have any web applications that I would like to use with Terracotta. Use the only the default applications."; 35 private static final String MESSAGE_TEXT_YES = "Copy web applications (.war only) from the following directory:"; 36 private static final String TITLE = "Select war Applications to Include in Sandbox"; 37 private JList list; 38 private JButton button; 39 private JTextField field; 40 private CustomCodePanelProxy panelProxy; 41 private String startDir; 42 43 public boolean setupUI(CustomCodePanelProxy customCodePanelProxy) { 44 panelProxy = customCodePanelProxy; 45 startDir = (String ) panelProxy.getVariable("lax.nl.env.CATALINA_HOME"); 46 if (startDir == null) startDir = panelProxy.getVariable("SYSTEM_DRIVE_ROOT").toString(); 47 48 JPanel p = new JPanel (); 49 p.setOpaque(false); 50 p.setLayout(new GridBagLayout ()); 51 GridBagConstraints c = new GridBagConstraints (); 52 c.fill = GridBagConstraints.BOTH; 53 c.insets = new Insets (1, 1, 16, 1); 54 c.anchor = GridBagConstraints.NORTHWEST; 55 56 c.gridx = 0; 57 c.gridy = 0; 58 c.weightx = 1; 59 c.weighty = 0; 60 p.add(choicePanel(), c); 61 62 c.gridx = 0; 63 c.gridy = 1; 64 c.weightx = 1; 65 c.weighty = 0; 66 p.add(browserPanel(), c); 67 68 list = new JList (); 69 list.setBackground(Color.WHITE); 70 JScrollPane scroll = new JScrollPane (list); 71 72 c.gridy = 2; 73 c.weighty = 1; 74 c.insets = new Insets (1, 1, 1, 1); 75 p.add(scroll, c); 76 add(p); 77 78 return true; 79 } 80 81 private JPanel browserPanel() { 82 JPanel p = new JPanel (); 83 p.setOpaque(false); 84 p.setLayout(new GridBagLayout ()); 85 GridBagConstraints c = new GridBagConstraints (); 86 c.fill = GridBagConstraints.HORIZONTAL; 87 c.insets = new Insets (0, 0, 0, 0); 88 c.anchor = GridBagConstraints.CENTER; 89 c.gridx = 0; 90 c.gridy = 0; 91 c.weightx = 1; 92 c.weighty = 0; 93 94 field = new JTextField (); 95 field.setFocusable(false); 96 97 button = new JButton ("Choose..."); 98 button.addActionListener(new ActionListener () { 99 public void actionPerformed(ActionEvent e) { 100 if (!field.getText().trim().equals("")) { 101 try { 102 new File (field.getText()); 103 startDir = field.getText(); 104 } catch (Exception ee) { 105 } 107 } 108 JFileChooser fileChooser = new JFileChooser (startDir); 109 fileChooser.setDialogTitle("Browse for .war Application Directory"); 110 fileChooser.setDragEnabled(false); 111 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 112 fileChooser.setMultiSelectionEnabled(false); 113 114 int returnValue = fileChooser.showDialog(new JFrame (), "OK"); 115 if (returnValue == JFileChooser.APPROVE_OPTION) { 116 File warDir = fileChooser.getSelectedFile(); 117 field.setText(warDir.getAbsolutePath()); 118 119 FileFilter filter = new WarFileFilter(); 121 File [] warList = new File (warDir.getAbsolutePath()).listFiles(filter); 122 ArrayList wars = new ArrayList (); 123 for (int i = 0; i < warList.length; i++) { 124 wars.add(warList[i].getName()); 125 } 126 127 list.setListData(wars.toArray()); 129 int size = list.getModel().getSize(); 130 int[] indices = new int[size]; 131 for (int i = 0; i < size; i++) { 132 indices[i] = i; 133 } 134 list.setSelectedIndices(indices); 135 } 136 } 137 }); 138 button.setFont(getFont()); 139 140 p.add(field, c); 141 c.gridx = 1; 142 c.weightx = 0; 143 c.insets = new Insets (0, 6, 0, 0); 144 p.add(button, c); 145 146 return p; 147 } 148 149 private JPanel choicePanel() { 150 JRadioButton yesWars = new JRadioButton (); 151 yesWars.setBackground(Color.WHITE); 152 yesWars.setActionCommand("yesWars"); 153 yesWars.setSelected(true); 154 yesWars.addActionListener(new ActionListener () { 155 public void actionPerformed(ActionEvent e) { 156 list.setEnabled(true); 157 button.setEnabled(true); 158 field.setEditable(true); 159 } 160 }); 161 JRadioButton noWars = new JRadioButton (); 162 noWars.setBackground(Color.WHITE); 163 noWars.setActionCommand("noWars"); 164 noWars.setSelected(false); 165 noWars.addActionListener(new ActionListener () { 166 public void actionPerformed(ActionEvent e) { 167 list.setEnabled(false); 168 list.getSelectionModel().clearSelection(); 169 button.setEnabled(false); 170 field.setEditable(false); 171 } 172 }); 173 174 ButtonGroup group = new ButtonGroup (); 175 group.add(yesWars); 176 group.add(noWars); 177 178 JTextPane msgYes = new JTextPane (); 179 msgYes.setOpaque(false); 180 msgYes.setEditable(false); 181 msgYes.setFont(getFont()); 182 msgYes.setText(MESSAGE_TEXT_YES); 183 184 JTextPane msgNo = new JTextPane (); 185 msgNo.setOpaque(false); 186 msgNo.setEditable(false); 187 msgNo.setFont(getFont()); 188 msgNo.setText(MESSAGE_TEXT_NO + "\n"); 189 190 JPanel msgPanel = new JPanel (); 191 msgPanel.setOpaque(false); 192 msgPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory 193 .createEmptyBorder(3, 3, 3, 3))); 194 msgPanel.setLayout(new GridBagLayout ()); 195 196 GridBagConstraints gbc = new GridBagConstraints (); 197 gbc.fill = GridBagConstraints.HORIZONTAL; 198 gbc.insets = new Insets (4, 0, 0, 0); 199 gbc.anchor = GridBagConstraints.NORTHWEST; 200 gbc.gridx = 0; 201 gbc.gridy = 0; 202 gbc.weightx = 1; 203 gbc.weighty = 1; 204 msgPanel.add(noWars, gbc); 205 gbc.insets = new Insets (0, 0, 0, 0); 206 gbc.gridx = 1; 207 gbc.weightx = 100; 208 msgPanel.add(msgNo, gbc); 209 gbc.insets = new Insets (4, 0, 0, 0); 210 gbc.gridx = 0; 211 gbc.gridy = 1; 212 gbc.weightx = 1; 213 msgPanel.add(yesWars, gbc); 214 gbc.insets = new Insets (0, 0, 0, 0); 215 gbc.gridx = 1; 216 gbc.weightx = 100; 217 msgPanel.add(msgYes, gbc); 218 return msgPanel; 219 } 220 221 public boolean okToContinue() { 222 Object [] wars = list.getSelectedValues(); 223 for (int i = 0; i < wars.length; i++) { 224 panelProxy.setVariable("USR_CP_WAR_" + i, panelProxy.substitute(wars[i].toString())); 225 } 226 return true; 227 } 228 229 public String getTitle() { 230 return TITLE; 231 } 232 } 233 | Popular Tags |