private boolean add() { // Validation: if (StringUtil.isEmpty(jtf_fileName.getText())) { JOptionPane.showMessageDialog( this, "Name must be present!", "Validation: name empty!", JOptionPane.ERROR_MESSAGE); jtf_fileName.requestFocus(); return false; } // Read values: final String fileName = jtf_fileName.getText(); final ContentType ct = jp_contentType.getContentType(); final File file = new File(jtf_file.getText()); final ReqEntityFilePart part = new ReqEntityFilePartBean(fileName, ct, file); // Trigger all listeners: for (AddMultipartPartListener l : listeners) { l.addPart(part); } // Clear: clear(); // Focus: jb_file.requestFocus(); return true; }
@PostConstruct protected void init() { // Button listeners: jb_add.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { add(); } }); jb_addAndClose.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addAndClose(); } }); jb_cancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }); jb_file.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectFile(); } }); // Default button: getRootPane().setDefaultButton(jb_add); // Layout: Container c = getContentPane(); c.setLayout(new BorderLayout()); { // Center JPanel jp = new JPanel(new BorderLayout()); JPanel jp_west = new JPanel(new GridLayout(3, 2)); jp_west.add(new JLabel(" Content type: ")); jp_west.add(new JLabel(" File name: ")); jp_west.add(new JLabel(" File: ")); jp.add(jp_west, BorderLayout.WEST); JPanel jp_center = new JPanel(new GridLayout(3, 2)); jp_center.add(jp_contentType.getComponent()); jp_center.add(UIUtil.getFlowLayoutPanelLeftAligned(jtf_fileName)); JPanel jp_file = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp_file.add(jtf_file); jp_file.add(jb_file); jp_center.add(jp_file); jp.add(jp_center, BorderLayout.CENTER); c.add(jp, BorderLayout.CENTER); } { // South JPanel jp = new JPanel(); jp.setLayout(new FlowLayout(FlowLayout.RIGHT)); jp.add(jb_cancel); jp.add(jb_add); jp.add(jb_addAndClose); c.add(jp, BorderLayout.SOUTH); } pack(); }
@Override public void setVisible(boolean boo) { jp_contentType.requestFocus(); super.setVisible(boo); }
@Override public void clear() { jp_contentType.clear(); jtf_fileName.setText(""); jtf_file.setText(""); }