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
|
import javax.swing.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.Color;
import java.util.Vector ;
import javax.swing.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.* ;
import java.io.*;
import java.sql.*;
//import oracle.jdbc.driver.*;
import java.lang.* ;
import java.util.ArrayList ;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
//import javax.swing.AbstractListModel;
class SortedListModel extends AbstractListModel {
SortedSet<Object> model;
public SortedListModel() {
model = new TreeSet<Object>();
}
public int getSize() {
return model.size();
}
public Object getElementAt(int index) {
return model.toArray()[index];
}
public void add(Object element) {
if (model.add(element)) {
fireContentsChanged(this, 0, getSize());
}
}
public void addAll(Object elements[]) {
Collection<Object> c = Arrays.asList(elements);
model.addAll(c);
fireContentsChanged(this, 0, getSize());
}
public void clear() {
model.clear();
fireContentsChanged(this, 0, getSize());
}
public boolean contains(Object element) {
return model.contains(element);
}
public Object firstElement() {
return model.first();
}
public Iterator iterator() {
return model.iterator();
}
public Object lastElement() {
return model.last();
}
public boolean removeElement(Object element) {
boolean removed = model.remove(element);
if (removed) {
fireContentsChanged(this, 0, getSize());
}
return removed;
}
}
//class TestLogic_Resto extends JPanel implements ActionListener,ListSelectionListener
class TestLogic_Resto extends JPanel implements ListSelectionListener
{
SortedListModel sourceListModel,cibleListModel;
JList sourceList,cibleList;
JScrollPane AvecAscsourceList,AvecAsccibleList ;
Dimension DimsourceList,DimcibleList;
//DefaultListModel Enveloppe ;
JTextArea topTextArea ;
String ChoixsourceList ;
String Sinstdep,Shostdep,Shostarr,Slogflashcopie,cmd2 ;
String[] strip1={"","",""} ;
public TestLogic_Resto() {
//liste source
sourceListModel = new SortedListModel(); // SortedListModel
sourceList = new JList(sourceListModel); //JList
AvecAscsourceList = new JScrollPane(sourceList) ;
DimsourceList = new Dimension(90,150) ;
AvecAscsourceList.setPreferredSize(DimsourceList) ;
sourceList.addListSelectionListener(this) ;
//liste cible
cibleListModel = new SortedListModel(); // SortedListModel
cibleList = new JList(cibleListModel); //JList
AvecAsccibleList = new JScrollPane(cibleList) ;
cibleList.addListSelectionListener(this) ;
//Zone affichage
topTextArea = new JTextArea();
topTextArea.setEditable(false);
JScrollPane topScrollPane = new JScrollPane(topTextArea);
Dimension preferredSize = new Dimension(850, 200);
topScrollPane.setPreferredSize(preferredSize);
//
this.add(AvecAscsourceList) ;
this.add(AvecAsccibleList) ;
this.add(topScrollPane) ;
addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2q80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2a80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2f80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2t80@02fhob:156701a001dbs:156701a02fhob:/cadnat/save/DS_v6.0.1/log/" });
addSourceElements(sourceListModel,new String[] { "ou7p80@001dbs->ou7q80@033ora:156701a001dbs:156701a033ora:/cadnat/save/DS_v6.0.1/log/" });
//topTextArea.append("toto") ;
}
public void valueChanged(ListSelectionEvent evt)
{
if (evt.getSource() == sourceList )
{
if ( evt.getValueIsAdjusting())
{
ChoixsourceList=(String)sourceList.getSelectedValue() ;
Sinstdep=ChoixsourceList.substring(0,6) ;
strip1=ChoixsourceList.split(":") ;
Shostdep=strip1[1] ;
Shostarr=strip1[2] ;
Slogflashcopie=strip1[3] ;
cmd2="rsh "+Shostdep+" -l root \"cat "+Slogflashcopie+Sinstdep+"/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"" ;
clearListModel(cibleListModel) ;
Alim_Resu_Univ(cmd2) ;
//addSourceElements(cibleListModel,new String[] {"vide"}) ;
}
}
}
//
/*
public void addSourceElements(ListModel newValue) {
fillListModel(sourceListModel, newValue);
}
public void addSourceElements(Object newValue[]) {
fillListModel(sourceListModel, newValue);
}
public void addCibleElements(ListModel newValue) {
fillListModel(cibleListModel, newValue);
}
public void addCibleElements(Object newValue[]) {
fillListModel(cibleListModel, newValue);
}
*/
public void addSourceElements(SortedListModel malistemodel,ListModel newValue) {
fillListModel(malistemodel, newValue);
}
public void addSourceElements(SortedListModel malistemodel,Object newValue[]) {
fillListModel(malistemodel, newValue);
}
private void fillListModel(SortedListModel model, ListModel newValues) {
int size = newValues.getSize();
for (int i = 0; i < size; i++) {
model.add(newValues.getElementAt(i));
}
}
private void fillListModel(SortedListModel model, Object newValues[]) {
model.addAll(newValues);
}
public void clearListModel(SortedListModel model) {
model.clear();
}
//
public void Alim_Resu_Univ(String shell)
{
try {
String[] cmdi = { "/bin/sh", "-c", shell };
//String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
//String cmd="/cadnat/ctige/script/java/test.sh" ;
Runtime runtime2 = Runtime.getRuntime();
final Process process2 = runtime2.exec(cmdi);
// Consommation de la sortie standard de l'application externe dans un Thread separe
new Thread() {
public void run() {
try {
BufferedReader reader2 = new BufferedReader(new InputStreamReader(process2.getInputStream()));
String line = "";
try {
//Enveloppe.clear();
while((line = reader2.readLine()) != null) {
// Traitement du flux de sortie de l'application si besoin est
//topTextArea.append(line+"\n") ;
addSourceElements(cibleListModel,new String[] {line.substring(0,17)}) ;
//Enveloppe.addElement(line.substring(0,17)) ;
}
//ChoixResuuniv="" ;
//
//LResuUniv.validate() ;
//
} finally {
reader2.close();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
// Consommation de la sortie d'erreur de l'application externe dans un Thread separe
new Thread() {
public void run() {
try {
BufferedReader reader3 = new BufferedReader(new InputStreamReader(process2.getErrorStream()));
String line = "";
try {
while((line = reader3.readLine()) != null) {
// Traitement du flux d'erreur de l'application si besoin est
topTextArea.append("\n"+line+"\n") ;
}
} finally {
reader3.close();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
}
catch(Exception e)
{
topTextArea.append(e.getMessage()) ;
//topTextArea.append(e.printStackTrace());
}
}
//
private static void showgui()
{
JFrame bt = new JFrame("Resto_Base") ;
bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = bt.getContentPane() ;
c.setLayout(new BorderLayout()) ;
TestLogic_Resto ma = new TestLogic_Resto() ;
c.add(ma) ;
bt.setSize(1400,500) ;
bt.setVisible(true) ;
}
public static void main (String [] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
showgui() ;
}
});
}
} |
Partager