package projetV1;
import java.util.ArrayList;
import java.sql.ResultSet;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
public class AdminPanel extends Dialog {
protected Object result;
protected Shell shlPanneauDadministration;
private Table tableTerme;
private Text text;
private Table tableUsers;
private Text text_1;
private ResultSet rs;
private Text host;
private Text dbname;
private Text username;
private Text password;
/**
* Create the dialog.
* @param parent
* @param style
*/
public AdminPanel(Shell parent, int style) {
super(parent, style);
}
/**
* Open the dialog.
* @return the result
*/
public Object open() {
createContents();
int x = (getParent().getShell().getLocation().x + (getParent()
.getShell().getSize().x / 2)) - (shlPanneauDadministration.getSize().x) / 2;
int y = (getParent().getShell().getLocation().y + (getParent()
.getShell().getSize().y / 2)) - (shlPanneauDadministration.getSize().y) / 2;
shlPanneauDadministration.setLocation(x, y);
shlPanneauDadministration.open();
shlPanneauDadministration.layout();
Display display = getParent().getDisplay();
while (!shlPanneauDadministration.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
getParent().getShell().setEnabled(true);
getParent().getShell().setVisible(true);
getParent().getShell().setActive();
return result;
}
/**
* Create contents of the dialog.
*/
private void createContents() {
shlPanneauDadministration = new Shell(getParent(), getStyle());
shlPanneauDadministration.setSize(565, 496);
shlPanneauDadministration.setText("Panneau d'administration");
TabFolder tabFolder = new TabFolder(shlPanneauDadministration, SWT.NONE);
tabFolder.setBounds(10, 10, 539, 450);
TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
tbtmNewItem.setText("Gestionnaire des termes");
Composite composite = new Composite(tabFolder, SWT.NONE);
tbtmNewItem.setControl(composite);
tableTerme = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION);
tableTerme.setLinesVisible(true);
tableTerme.setBounds(10, 43, 511, 312);
tableTerme.setHeaderVisible(true);
// resize the row height using a MeasureItem listener
tableTerme.addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
// height cannot be per row so simply set
event.height = 30;
// event.width=50;
}
});
// final TableEditor editor = new TableEditor(table);
// // The editor must have the same size as the cell and must
// // not be any smaller than 50 pixels.
// editor.horizontalAlignment = SWT.LEFT;
// editor.grabHorizontal = true;
// editor.minimumWidth = 50;
// // editing the second column
// final int EDITABLECOLUMN=0;
//
//
// table.addSelectionListener(new SelectionAdapter() {
// public void widgetSelected(SelectionEvent e) {
// // Clean up any previous editor control
// Control oldEditor = editor.getEditor();
// if (oldEditor != null)
// oldEditor.dispose();
//
// // Identify the selected row
// TableItem item = (TableItem) e.item;
// if (item == null)
// return;
// for (int i=0; i<table.getColumnCount(); i++){
//
// // The control that will be the editor must be a child of the
// // Table
// Text newEditor = new Text(table, SWT.NONE);
// newEditor.setText(item.getText(i+1));
// final int j=i+1;
// newEditor.addModifyListener(new ModifyListener() {
// public void modifyText(ModifyEvent me) {
// Text text = (Text) editor.getEditor();
// editor.getItem().setText(j, text.getText());
// }
// });
// newEditor.selectAll();
// newEditor.setFocus();
// editor.setEditor(newEditor, item, i);
// }
// }
//
// });
final DbConn bd=new DbConn();
TableColumn tblclmnTerme = new TableColumn(tableTerme, SWT.CENTER);
tblclmnTerme.setWidth(100);
tblclmnTerme.setText("Terme");
TableColumn tblclmnNewColumn_1 = new TableColumn(tableTerme, SWT.CENTER);
tblclmnNewColumn_1.setWidth(100);
tblclmnNewColumn_1.setText("Prononciation");
TableColumn tblclmnNewColumn_2 = new TableColumn(tableTerme, SWT.CENTER);
tblclmnNewColumn_2.setWidth(100);
tblclmnNewColumn_2.setText("Nature");
TableColumn tblclmnNewColumn_3 = new TableColumn(tableTerme, SWT.CENTER);
tblclmnNewColumn_3.setWidth(100);
tblclmnNewColumn_3.setText("D\u00E9finition");
TableColumn tblclmnNewColumn_4 = new TableColumn(tableTerme, SWT.CENTER);
tblclmnNewColumn_4.setWidth(100);
tblclmnNewColumn_4.setText("Propos\u00E9 par");
Combo combo = new Combo(composite, SWT.NONE);
combo.setItems(new String[] {"Ajout", "Modification"});
combo.setBounds(330, 14, 105, 23);
combo.select(0);
Combo numPage = new Combo(composite, SWT.NONE);
numPage.setBounds(476, 14, 45, 23);
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setBounds(441, 17, 29, 15);
lblNewLabel.setText("Page:");
text = new Text(composite, SWT.BORDER);
text.setBounds(63, 16, 125, 21);
Label lblChercher = new Label(composite, SWT.NONE);
lblChercher.setBounds(10, 17, 55, 15);
lblChercher.setText("Chercher:");
Label lblOpration = new Label(composite, SWT.NONE);
lblOpration.setBounds(269, 17, 55, 15);
lblOpration.setText("Op\u00E9ration:");
TabItem tbtmNewItem_1 = new TabItem(tabFolder, SWT.NONE);
tbtmNewItem_1.setText("Gestionnaire des utilisateurs");
Composite composite_1 = new Composite(tabFolder, SWT.NONE);
tbtmNewItem_1.setControl(composite_1);
tableUsers = new Table(composite_1, SWT.BORDER | SWT.FULL_SELECTION);
tableUsers.setLinesVisible(true);
tableUsers.setHeaderVisible(true);
tableUsers.setBounds(10, 43, 511, 312);
TableColumn tblclmnNomDutilisateur = new TableColumn(tableUsers, SWT.CENTER);
tblclmnNomDutilisateur.setWidth(100);
tblclmnNomDutilisateur.setText("Nom d'utilisateur");
TableColumn tblclmnNom = new TableColumn(tableUsers, SWT.CENTER);
tblclmnNom.setWidth(100);
tblclmnNom.setText("Mot de passe");
TableColumn tblclmnPrnom = new TableColumn(tableUsers, SWT.CENTER);
tblclmnPrnom.setWidth(100);
tblclmnPrnom.setText("Pr\u00E9nom");
TableColumn tblclmnEmail = new TableColumn(tableUsers, SWT.CENTER);
tblclmnEmail.setWidth(100);
tblclmnEmail.setText("Nom");
TableColumn tblclmnNewColumn = new TableColumn(tableUsers, SWT.CENTER);
tblclmnNewColumn.setWidth(100);
tblclmnNewColumn.setText("E-mail");
Combo combo_3 = new Combo(composite_1, SWT.NONE);
combo_3.setBounds(476, 14, 45, 23);
Label label = new Label(composite_1, SWT.NONE);
label.setText("Page:");
label.setBounds(441, 17, 29, 15);
text_1 = new Text(composite_1, SWT.BORDER);
text_1.setBounds(63, 16, 125, 21);
Label label_1 = new Label(composite_1, SWT.NONE);
label_1.setText("Chercher:");
label_1.setBounds(10, 17, 55, 15);
TabItem configurationItm = new TabItem(tabFolder, SWT.NONE);
configurationItm.setText("Configuration");
Composite composite_3 = new Composite(tabFolder, SWT.NONE);
configurationItm.setControl(composite_3);
Label lblHote = new Label(composite_3, SWT.NONE);
lblHote.setBounds(90, 58, 55, 15);
lblHote.setText("Hote:");
Label lblNomDeLa = new Label(composite_3, SWT.NONE);
lblNomDeLa.setBounds(90, 85, 149, 15);
lblNomDeLa.setText("Nom de la base de donn\u00E9es:");
Label lblNomDutilisateur = new Label(composite_3, SWT.NONE);
lblNomDutilisateur.setBounds(90, 112, 107, 15);
lblNomDutilisateur.setText("Nom d'utilisateur:");
Label lblMotDePasse = new Label(composite_3, SWT.NONE);
lblMotDePasse.setBounds(90, 140, 93, 15);
lblMotDePasse.setText("Mot de passe:");
host = new Text(composite_3, SWT.BORDER);
host.setBounds(258, 55, 165, 21);
host.setText(bd.getHost());
dbname = new Text(composite_3, SWT.BORDER);
dbname.setBounds(258, 82, 165, 21);
dbname.setText(bd.getDbname());
username = new Text(composite_3, SWT.BORDER);
username.setBounds(258, 109, 165, 21);
username.setText(bd.getUsername());
password = new Text(composite_3, SWT.BORDER | SWT.PASSWORD);
password.setBounds(258, 137, 165, 21);
password.setText(bd.getPassword());
Button btnNewButton = new Button(composite_3, SWT.NONE);
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
bd.setConfig(host.getText(), dbname.getText(), username.getText(), password.getText());
}
});
btnNewButton.setBounds(348, 181, 75, 25);
btnNewButton.setText("Enregistrer");
TabItem tbtmNewItem_2 = new TabItem(tabFolder, SWT.NONE);
tbtmNewItem_2.setText("Statistiques");
Composite composite_2 = new Composite(tabFolder, SWT.NONE);
tbtmNewItem_2.setControl(composite_2);
Label lblNombreDesMots = new Label(composite_2, SWT.NONE);
lblNombreDesMots.setBounds(10, 10, 238, 15);
lblNombreDesMots.setText("Nombre des mots:");
Label lblNombreDesUtilisateurs = new Label(composite_2, SWT.NONE);
lblNombreDesUtilisateurs.setText("Nombre des utilisateurs:");
lblNombreDesUtilisateurs.setBounds(10, 76, 238, 15);
Label lblNombreDesMots_1 = new Label(composite_2, SWT.NONE);
lblNombreDesMots_1.setText("Nombre des mots non confirm\u00E9s:");
lblNombreDesMots_1.setBounds(10, 42, 238, 15);
DbConn db = new DbConn();
db.connect();
ArrayList<ArrayList> a=new ArrayList<ArrayList>();
a=db.sqlQuery("SELECT * FROM fr_fr LIMIT 0 , 30");
int nbrTerme=0;
try{
nbrTerme = Integer.parseInt(db.sqlQuery("SELECT COUNT(*) FROM fr_fr").get(0).get(0).toString());
}
catch(Exception e){
}
int nbPage=1;
for (int j=0; j<nbrTerme; j+=30){
numPage.add(""+nbPage);
nbPage++;
}
for (int i=0; i<a.size(); i++){
ArrayList<String> al=a.get(i);
String[] s=new String[al.size()];
for (int j=0; j<al.size(); j++){
s[j]=al.get(j).toString();
}
TableItem item = new TableItem(tableTerme, SWT.NONE);
item.setText(s);
}
a.clear();
a=db.sqlQuery("SELECT * FROM users LIMIT 0 , 30");
for (int i=0; i<a.size(); i++){
ArrayList<String> al=a.get(i);
String[] s=new String[al.size()];
for (int j=0; j<al.size(); j++){
s[j]=al.get(j).toString();
}
TableItem item = new TableItem(tableUsers, SWT.NONE);
item.setText(s);
}
db.disconnect();
}
}