1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
/**
* Ajout de tps dans la table
*/
public void addTps(){
boolean find=false;
for(Enumeration<TpsRef> en=Variable.baseTps.elements();en.hasMoreElements();){
boolean ok=false;
TpsRef r=en.nextElement();
String name = r.getNameTps().toUpperCase();
String produit = r.getProduit().toUpperCase();
String PN = r.getPN().toUpperCase();
String CMM = r.getCMM().toUpperCase();
String etat = Variable.etatName[r.getEtat()].toUpperCase();
if(!(((MyTableModel)table.getModel()).getSelect().containsKey(name))){
if(fAddTPS.getText().toUpperCase().equals("")){
ok=true;
}else{
StringTokenizer s=new StringTokenizer(fAddTPS.getText().toUpperCase(),"|");
while(s.hasMoreTokens()&&!ok){
boolean and=true;
String regex="";
StringTokenizer st=new StringTokenizer(s.nextToken(),"#&");
while(st.hasMoreTokens()&&and){
regex=st.nextToken();
if(!(name.contains(regex)||
produit.contains(regex)||
PN.contains(regex)||
CMM.contains(regex)||
etat.contains(regex))){
and=false;
}
}
if(and){
ok=true;
}
}
}
if(ok){
if(!find){
find=true;
fAddTPS.setBackground(Color.GREEN);
}
((MyTableModel)table.getModel()).addRow(name);
}
}
}
if(!find) fAddTPS.setBackground(Color.RED);
else ((MyTableModel)table.getModel()).fireTableDataChanged();
}
/**
* Fonction de scan des TPS (fonction du champ search)
*/
public void newFilter(){
// Filtre les mauvais caractères
String test = search.getText().replaceAll("[\\[\\(\\)]","");
//search.setText(test);
RowFilter<MyTableModel, Object> rf = null;
Vector<RowFilter<Object, Object>> v = new Vector<RowFilter<Object, Object>>();
StringTokenizer st=new StringTokenizer(test,"#&");
while(st.hasMoreTokens()){
String temp=st.nextToken();
v.add(RowFilter.regexFilter("(?i)"+temp));
}
sorter.setRowFilter(RowFilter.andFilter(v));
// try {
// rf = RowFilter.regexFilter(search.getText());
// } catch (java.util.regex.PatternSyntaxException e) {
// return;
// }
// sorter.setRowFilter(rf);
}
/**Fonction permettant de faire appel à un programme qui sera créé par une autre personne, se sera un programme d'installation automatique**/
public void initExec() {
String cmd;
cmd="cmd /C C:\\chemin_et_nom du programme";
try{
Runtime run = Runtime.getRuntime();
Process p = run.exec(cmd);
p.waitFor(); /**Attendre le fin du processus du programme lancé**/
}catch (Exception e){
Variable.out.println("Erreur d'éxécution :"+cmd+e.toString());
}
}
/**
* Methode de gestion du JButton Install
* Install les tps sur tous les postes
*/
public void installerAll(){
String sup="";
String comp=null;
for(Enumeration<Poste> et=retouracceuil.postes_selectionnes.elements();et.hasMoreElements();){
if(comp==null){
comp=et.nextElement().getGroupe().getNom();
}else if(!comp.equals(et.nextElement().getGroupe().getNom())){
sup="ATTENTION il y a plus d'un groupes différents.\n";
break;
}
}
int choix = JOptionPane.showConfirmDialog(null,sup+"Êtes vous sûr d'installer les tps sur tout les PC ?", "Confirmation",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); /**Affichage de la fenêtre de dialogue demandant la confirmation d'installation **/
if (choix == JOptionPane.YES_OPTION) /**Gestion de l'ajout et de la suppression des groupes en graphique et dans le fichier txt**/
{
Object[] options = { Variable.etatName[Variable.OPERATIONEL], Variable.etatName[Variable.TEMP] };
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
MyTableModel md=(MyTableModel)table.getModel();
for(int i=0;i<md.getRowCount();i++){
if((md.getValueAt(i,md.getColumnCount()-1)).equals(true)){
TpsRef ref = Variable.baseTps.get((String)md.getValueAt(i,1));
if(ref!=null){
if(ref.getEtat()==Variable.NEW){
Object choix2 = JOptionPane.showInputDialog(null,"Choix pour le tps : "+ref.getNameTps(),"Warning",
JOptionPane.INFORMATION_MESSAGE,null,options,options[0]);
if(choix2!=null){
int oldEtat=ref.getEtat();
int newEtat=Variable.nameEtat(choix2.toString());
String subTps=ref.getNameTps().replaceFirst("^[\\d]+-","");
String sourceZip=Variable.subRep(subTps,ref.getInstallDir());
String destZip=Variable.modifInstall(sourceZip,oldEtat,newEtat);
if(destZip==null){
Variable.err.println("Modification impossible car pas de dossier de référence pour "+Variable.etatName[newEtat]);
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
continue;
}else if(destZip.equals("")){
Variable.err.println("Modification impossible car le fichier d'install n'est pas dans un dossier de référence pour "+Variable.etatName[oldEtat]);
continue;
}
Variable.out.println(sourceZip+" -> "+destZip);
if(!new File(destZip.toUpperCase().replaceAll("\\\\\\w*.ZIP","\\\\")).exists()){
if(!new File(destZip.replaceAll("[^\\\\]+\\\\$","")).exists()){
if(!new File(destZip.replaceAll("[^\\\\]+\\\\$","")).mkdirs()){
Variable.err.println("Erreur de création de répertoire : "+destZip);
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
continue;
}
}
}
if(new File(sourceZip).renameTo(new File(destZip))){
ref.setInstallDir(Variable.modifInstall(ref.getInstallDir(),oldEtat,newEtat));
ref.setEtat(newEtat);
md.setValueAt(Variable.etatName[newEtat],i,md.getColumnCount()-3);
// this.installRef.setText(ref.getInstallDir());
String s=Variable.deleteRec(sourceZip.replaceAll("[^\\\\]+\\\\$",""),sourceZip);
s = s!=null ? s : sourceZip;
Variable.out.println("Fichier/Dossier supprimé : "+s);
Variable.out.println("Fichier déplacé : "+sourceZip+" -> "+destZip);
Variable.saveRef();
}else{
Variable.err.println("Erreur pour déplacer le fichier : "+sourceZip+" -> "+destZip);
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
continue;
}
}else{
Variable.err.println("Pas de choix pour le tps "+ref.getNameTps());
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
continue;
}
}
Variable.out.println("Install auto de ["+ref.getNameTps()+"]");
for(int k=3;k<md.getColumnCount()-4;k++){
Object []temp = ((Cell)md.getValueAt(i,k)).o;
String name = (String)temp[0];
Poste p = (Poste)temp[1];
Vector<TpsPoste> t=(Vector<TpsPoste>)temp[2];
if(t==null){
p.installTps(name);
}else{
if(!p.isTpsRef(name)){
Variable.out.println(md.getColumnName(k)+" to REF : "+(String)md.getValueAt(i,1));
p.addRef(name);
}
}
}
}else{
Variable.err.println("Impossible d'installer un programme qui n'est pas une ref : ["+(String)md.getValueAt(i,1)+"]");
}
md.setValueAt(false,i,md.getColumnCount()-1);
}
}
md.fireTableDataChanged();
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
/** Méthode à exécuter à partir de la class "Menu"
/**
* Class de gestion d'exportation
*/
// public class GestionExporter implements ActionListener /**Evènement du bouton 'Exporter'**/
// {
/**
* Methode d'exportation
* @param ev ActionEvent
*/
public void actionPerformedOne(ActionEvent ev) {
Variable.out.println("Le bouton 'Exporter' a été cliquer");
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
WritableWorkbook workbook = Workbook.createWorkbook(new File("sortie.xls"));
WritableSheet sheet = workbook.createSheet("Premier classeur", 0);
int nbRow = table.getRowCount();
int nbCol = table.getColumnCount();
for(int i=0;i<nbCol-2;i++){
sheet.addCell(new Label(i,0,(String)table.getModel().getColumnName(table.convertColumnIndexToModel(i))));
sheet.setColumnView(i,17);
}
Hashtable<Color,Colour> couleur = new Hashtable<Color,Colour>();
couleur.put(Color.RED,Colour.RED);
couleur.put(Color.GREEN,Colour.GREEN);
couleur.put(Color.BLUE,Colour.BLUE);
couleur.put(Color.CYAN,Colour.CORAL);
couleur.put(Color.WHITE,Colour.WHITE);
couleur.put(Color.GRAY,Colour.GRAY_50);
couleur.put(Color.LIGHT_GRAY,Colour.GRAY_25);
couleur.put(Color.MAGENTA,Colour.ROSE);
couleur.put(Color.ORANGE,Colour.ORANGE);
// for(int i=0;i<table.getModel().getRowCount();i++){
for(int i=0;i<nbRow;i++){
for(int j=0;j<nbCol-2;j++){
int ireal=table.convertRowIndexToModel(i);
int jreal=table.convertColumnIndexToModel(j);
if(!table.getValueAt(i,j).getClass().getName().equals("java.lang.String")){
Component c = table.getCellRenderer(ireal,j).getTableCellRendererComponent(table,table.getValueAt(i,j),false,false,i,j);
WritableFont w = new WritableFont(WritableFont.ARIAL, 10,WritableFont.BOLD, true, UnderlineStyle.NO_UNDERLINE,Colour.WHITE, ScriptStyle.NORMAL_SCRIPT);
WritableCellFormat wc = new WritableCellFormat(w);
wc.setBackground(couleur.get(c.getBackground()));
sheet.addCell(new Label(j,i+1,"",wc));
}else{
sheet.addCell(new Label(j,i+1,(String)table.getValueAt(i,j)));
}
}
}
workbook.write();
workbook.close();
setCursor(null);
Runtime run= Runtime.getRuntime();
String cmd = "cmd /C start excel \"" + new File("sortie.xls").getAbsoluteFile()+"\"";
Runtime.getRuntime().exec(cmd);
} catch (RowsExceededException e1) {
e1.printStackTrace();
} catch (WriteException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
Variable.out.println("Le fichier \"sortie.xls\" à été généré correctement.");
}
}
// }
public int print(Graphics g, PageFormat pageFormat, int pageIndex)throws PrinterException {
Variable.out.println("99");
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.black);
Variable.out.println("101");
int fontHeight = g2.getFontMetrics().getHeight();
int fontDescent = g2.getFontMetrics().getDescent();
Variable.out.println("1010");
// laisser de l'espace pour le numero de page
double pageHeight = pageFormat.getImageableHeight() - fontHeight;
Variable.out.println("1011");
double pageWidth = pageFormat.getImageableWidth();
Variable.out.println("1012");
double tableWidth = (double)table.getColumnModel().getTotalColumnWidth();
Variable.out.println("1013");
double scale = 1;
Variable.out.println("102");
if (tableWidth >= pageWidth) {
Variable.out.println("103");
scale = pageWidth / tableWidth;
Variable.out.println("104");
}
Variable.out.println("105");
double headerHeightOnPage = table.getTableHeader().getHeight()*scale;
double tableWidthOnPage = tableWidth * scale;
double oneRowHeight = (table.getRowHeight() + table.getRowMargin())*scale;
int numRowsOnAPage = (int)((pageHeight-headerHeightOnPage) / oneRowHeight);
double pageHeightForTable = oneRowHeight * numRowsOnAPage;
int totalNumPages = (int)Math.ceil(((double)table.getRowCount()) / numRowsOnAPage);
Variable.out.println("106");
if (pageIndex >= totalNumPages)
return NO_SUCH_PAGE;
Variable.out.println("107");
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// en bas au centre
Variable.out.println("108");
g2.drawString("Page: " + (pageIndex +1),(int)pageWidth/2 - 35, (int)(pageHeight + fontHeight - fontDescent));
g2.translate(0f, headerHeightOnPage);
g2.translate(0f, -pageIndex*pageHeightForTable);
Variable.out.println("109");
// si cette partie de la page est plus petite
// que la taille disponible, alors découper les contours appropriés
if (pageIndex + 1 == totalNumPages) {
int lastRowPrinted = numRowsOnAPage * pageIndex;
int numRowsLeft = table.getRowCount() - lastRowPrinted;
g2.setClip(0, (int)(pageHeightForTable * pageIndex),(int)Math.ceil(tableWidthOnPage),(int)Math.ceil(oneRowHeight * numRowsLeft));
}
// sinon découper la zone disponible toute entière
else {
g2.setClip(0, (int)(pageHeightForTable * pageIndex),(int)Math.ceil(tableWidthOnPage),(int)Math.ceil(pageHeightForTable));
}
Variable.out.println("110");
g2.scale(scale, scale);
table.paint(g2);
// dessiner les entêtes en haut
Variable.out.println("111");
g2.scale(1/scale, 1/scale);
g2.translate(0f, pageIndex*pageHeightForTable);
g2.translate(0f, -headerHeightOnPage);
g2.setClip(0, 0,(int)Math.ceil(tableWidthOnPage),(int)Math.ceil(headerHeightOnPage));
g2.scale(scale, scale);
table.getTableHeader().paint(g2);
return Printable.PAGE_EXISTS;
}
}/**Fin de la classe Page3**/ |