initComponents();
panelToolBar.add(new CloseButton(this));
setToolBar(panelToolBar);
SimpleInternalFrame searchPanel = new SimpleInternalFrame(IconFactory
.createSearch(), "Pesquisa...");
JToolBar searchToolBar = new JToolBar();
JButton filterButton = new JButton();
actionFilter = new AbstractAction("", IconFactory.createSearch()) {
private static final long serialVersionUID = 256213712896508104L;
public void actionPerformed(ActionEvent e) {
Filter[] filters = getFilters();
FilterPipeline pipeline = new FilterPipeline(filters);
table.setFilters(pipeline);
editButton.setEnabled(false);
deleteButton.setEnabled(false);
}
};
filterButton.setAction(actionFilter);
filterButton.setToolTipText("Filtrar lista");
searchToolBar.add(filterButton);
JButton clearButton = new JButton();
Action actionClear = new AbstractAction("", IconFactory.createClear()) {
private static final long serialVersionUID = -1822399088483448296L;
public void actionPerformed(ActionEvent e) {
editButton.setEnabled(false);
deleteButton.setEnabled(false);
table.setFilters(new FilterPipeline());
clearFilterFields();
}
};
clearButton.setAction(actionClear);
clearButton.setToolTipText("Limpa filtros da lista");
searchToolBar.add(clearButton);
searchPanel.setToolBar(searchToolBar);
SimpleInternalFrame tablePanel = new SimpleInternalFrame("");
newButton = new JButton();
newButton.setAction(getNewAction());
newButton.setToolTipText("Novo");
newButton.setIcon(IconFactory.createNew());
newButton.setText("");
tableToolBar.add(newButton);
editButton.setAction(getEditAction());
editButton.setToolTipText("Modificar");
editButton.setEnabled(false);
tableToolBar.add(editButton);
deleteButton.setAction(getDeleteAction());
deleteButton.setToolTipText("Remover");
deleteButton.setEnabled(false);
tableToolBar.add(deleteButton);
tableToolBar.addSeparator();
Action actionRefresh = new AbstractAction("", IconFactory
.createRefresh()) {
private static final long serialVersionUID = 6721786157947228534L;
public void actionPerformed(ActionEvent e) {
((SearchTableModel) table.getModel()).refresh();
clearFilterFields();
enableButtons(false);
}
};
JButton refreshButton = new JButton();
refreshButton.setAction(actionRefresh);
refreshButton.setToolTipText("Atualiza lista");
tableToolBar.add(refreshButton);
Action actionSave = new AbstractAction("", IconFactory.createSave()) {
private static final long serialVersionUID = -6026875243019236791L;
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.showSaveDialog(null);
try {
String bean = BeanManager
.parseBeanToXML(((SearchTableModel) table
.getModel()).getList());
FileWriter fileWriter = new FileWriter(fileChooser
.getSelectedFile());
fileWriter.write(bean);
fileWriter.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IntrospectionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
};
JButton saveButton = new JButton();
saveButton.setAction(actionSave);
saveButton.setToolTipText("Salva a lista");
tableToolBar.add(saveButton);
Action actionPrint = new AbstractAction("", IconFactory.createPrint()) {
private static final long serialVersionUID = -6721786157947228534L;
public void actionPerformed(ActionEvent e) {
try {
table.print();
} catch (PrinterException e1) {
// TODO desenvolver tratamento de exce��es
e1.printStackTrace();
}
}
};
JButton printButton = new JButton();
printButton.setAction(actionPrint);
printButton.setToolTipText("Imprimir listagem");
tableToolBar.add(printButton);
tableToolBar.addSeparator();
tablePanel.setToolBar(tableToolBar);
JSplitPane iPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
searchPanel, tablePanel);
iPanel.setOneTouchExpandable(true);
add(iPanel);
searchPanel.add(getFilterPanel());
build();
for (TableColumn column : tableColumns) {
getTableModel().getColumnModel().addColumn(column);
}
table.setModel(getTableModel());
table.setColumnControlVisible(true);
JScrollPane spTable = new JScrollPane(table);
MouseListener tableMouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
int clicks = e.getClickCount();
if (clicks == 1) {
enableButtons(table.getSelectedRowCount() == 1);
deleteButton.setEnabled(table.getSelectedRowCount() > 0);
} if (clicks == 2) {
getEditAction().actionPerformed(null);
}
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
};
table.addMouseListener(tableMouseListener);
table.setColumnControlVisible(true);
table.setHighlighters(new HighlighterPipeline(
new Highlighter[] { new AlternateRowHighlighter() }));
tablePanel.add(spTable);
}