by blumbroso » Thu Sep 07, 2006 8:46 am
Hello,
I will try the demo QuickFilter within Eclipse SWT Shell and some features
doesn't work:
- pop menu on [?] filter button
- Edit cell doesn't accept key!!!
Do you know if i have to do something more to provide the compatibility?
I have to choose a powerfull library and JIDE is very attrative but we want to use RCP...
run my code please :
package eval;
import com.jidesoft.grid.*;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.JideSplitPane;
import com.jidesoft.swing.JideTitledBorder;
import com.jidesoft.swing.PartialEtchedBorder;
import com.jidesoft.swing.PartialSide;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;
import java.util.zip.GZIPInputStream;
/**
* Demoed Component: {@link com.jidesoft.grid.SortableTable}
* <br>
* Required jar files: jide-common.jar, jide-grids.jar
* <br>
* Required L&F: any L&F
*/
public class ExampleTable {
public ExampleTable() {
}
public Component getDemoPanel() {
final TableModel tableModel = createTableModel();
if (tableModel == null) {
return new JLabel("Failed to read Library.txt.gz");
}
final QuickFilterPane quickFilterPane = new QuickFilterPane(new SortableTableModel(tableModel), new int[]{3, 1, 2});
JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)) {
public void update(java.awt.Graphics g) {
/* Do not erase the background */
paint(g);
} };
QuickTableFilterField filterField = new QuickTableFilterField(quickFilterPane.getDisplayTableModel(), new int[]{1, 2, 0, 5});
quickSearchPanel.add(filterField);
quickSearchPanel.setBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "QuickTableFilterField", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP));
JideSplitPane pane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);
quickFilterPane.setBorder(BorderFactory.createCompoundBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "QuickFilterPane", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP),
BorderFactory.createEmptyBorder(6, 0, 0, 0)));
pane.addPane(quickFilterPane);
JPanel tablePanel = new JPanel(new BorderLayout(2, 2));
tablePanel.setBorder(BorderFactory.createCompoundBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Filtered Song List", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP),
BorderFactory.createEmptyBorder(0, 0, 0, 0)));
final JLabel label = new JLabel(filterField.getDisplayTableModel().getRowCount() + " out of " + tableModel.getRowCount() + " songs");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
SortableTable sortableTable = new SortableTable(filterField.getDisplayTableModel());
sortableTable.getColumnModel().getColumn(0).setPreferredWidth(200);
sortableTable.getColumnModel().getColumn(4).setPreferredWidth(60);
sortableTable.getColumnModel().getColumn(5).setPreferredWidth(60);
filterField.setTable(sortableTable);
JScrollPane scrollPane = new JScrollPane(sortableTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, TableColumnChooser.getTableColumnChooserButton(sortableTable,
new boolean[]{true, false, false, false, false, false}, new String[]{"Song Name", "Artist of the Song", "Album of the Song", "Genre of the Song", "Duration of the Song", "Year when the Song is published",}));
filterField.getDisplayTableModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
if (e.getSource() instanceof FilterableTableModel) {
int count = ((TableModel) e.getSource()).getRowCount();
label.setText(count + " out of " + tableModel.getRowCount() + " songs");
}
}
});
tablePanel.add(label, BorderLayout.BEFORE_FIRST_LINE);
tablePanel.add(scrollPane);
pane.addPane(tablePanel);
JPanel panel = new JPanel(new BorderLayout(3, 3));
panel.add(quickSearchPanel, BorderLayout.BEFORE_FIRST_LINE);
panel.add(pane);
// JButton resetButton = new JButton("Reset");
// resetButton.addActionListener(new AbstractAction(){
// public void actionPerformed(ActionEvent e) {
// ((AbstractTableModel) tableModel).fireTableDataChanged();
// }
// });
// panel.add(resetButton, BorderLayout.AFTER_LAST_LINE);
return panel;
}
private TableModel createTableModel() {
try {
InputStream resource = this.getClass().getClassLoader().getResourceAsStream("Library.txt.gz");
if (resource == null) {
return null;
}
InputStream in = new GZIPInputStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
Vector data = new Vector();
Vector columnNames = new Vector();
String columnsLine = reader.readLine(); // skip first line
String[] columnValues = columnsLine.split("\t");
for (int i = 0; i < columnValues.length; i++) {
String name = columnValues[i];
columnNames.add(name);
}
do {
String line = reader.readLine();
if (line == null || line.length() == 0) {
break;
}
String[] values = line.split("\t");
Vector lineData = new Vector();
if (values.length < 1)
lineData.add(null); // song name
else
lineData.add(values[0]); // song name
if (values.length < 2)
lineData.add(null); // artist
else
lineData.add(values[1]); // artist
if (values.length < 3)
lineData.add(null); // album
else
lineData.add(values[2]); // album
if (values.length < 4)
lineData.add(null); // genre
else
lineData.add(values[3]); // genre
if (values.length < 5)
lineData.add(null); // time
else
lineData.add(values[4]); // time
if (values.length < 6)
lineData.add(null); // year
else
lineData.add(values[5]); // year
data.add(lineData);
}
while (true);
DefaultTableModel tableModel = new DefaultTableModel(data, columnNames) {
public boolean isCellEditable(int row, int column) {
return true;
}
};
return tableModel;
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
public String getDemoFolder() {
return "G15. QuickFilter";
}
static public void main(String[] s) {
LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
ExampleTable et = new ExampleTable();
Shell shell = new Shell();
shell.setLayout(new org.eclipse.swt.layout.GridLayout());
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.grabExcessVerticalSpace = true;
org.eclipse.swt.widgets.Composite composite = new org.eclipse.swt.widgets.Composite(shell, SWT.NO_BACKGROUND |SWT.EMBEDDED);
composite.setLayout(new FillLayout());
composite.setLayoutData(gridData);
java.awt.Frame locationFrame = SWT_AWT.new_Frame(composite);
locationFrame.setLayout(new FlowLayout());
locationFrame.add(et.getDemoPanel());
Display display = shell.getDisplay();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
static public void mainInAllSwing(String[] s) {
LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
ExampleTable et = new ExampleTable();
JFrame jf = new JFrame();
jf.getContentPane().setLayout(new FlowLayout());
jf.add(et.getDemoPanel());
jf.setSize(800,800);
jf.setVisible(true);
}
}