PackagerGUI.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright (C) 2015 iZc
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package de.nplusc.izc.InstallPak.legacy;
  18. import de.nplusc.izc.InstallPak.Definitions;
  19. import de.nplusc.izc.InstallPak.Main;
  20. import de.nplusc.izc.tools.baseTools.HidableTableColumnModel;
  21. import de.nplusc.izc.tools.baseTools.Tools;
  22. import java.awt.Point;
  23. import javax.swing.table.DefaultTableModel;
  24. /**
  25. *
  26. * @author LH
  27. */
  28. public class PackagerGUI extends javax.swing.JFrame
  29. {
  30. /**
  31. * Creates new form PackagerGUI
  32. */
  33. private PackManager p;
  34. public PackagerGUI()
  35. {
  36. initComponents();
  37. updatePosition();
  38. lblVID.setText(Definitions.VERSION_GUI_TXT);
  39. packStatus.setVisible(false);
  40. p = new PackManager();
  41. p.loadPackageData(Main.filePath);
  42. ((HidableTableColumnModel)(tblSelector.getColumnModel())).setColumnVisible(0, false);
  43. //^auskommentieren um id-spalte sichtbar zu bekommenTempcode fürs Testen
  44. int rows=1;
  45. String[] tablefill = p.getPackList();
  46. for (int i = 0; i < tablefill.length; i++)
  47. {
  48. String GRP = tablefill[i];
  49. String[] data = GRP.split("\\|");
  50. if(i>=rows)
  51. ((DefaultTableModel)tblSelector.getModel()).addRow(new String[3]);
  52. ((DefaultTableModel)tblSelector.getModel()).setValueAt(data[0], i, 0);
  53. ((DefaultTableModel)tblSelector.getModel()).setValueAt(data[1], i, 1);
  54. ((DefaultTableModel)tblSelector.getModel()).setValueAt("Wird installiert", i, 2);
  55. if(p.packIsInstalled(data[0]))
  56. {
  57. ((DefaultTableModel)tblSelector.getModel()).setValueAt("Bereits installiert", i, 2);
  58. }
  59. }
  60. }
  61. private void updatePosition()
  62. {
  63. Point p = new Point(Main.topleft_coords_x, Main.topleft_coords_y);
  64. setLocation(p);
  65. }
  66. /**
  67. * This method is called from within the constructor to
  68. * initialize the form.
  69. * WARNING: Do NOT modify this code. The content of this method is
  70. * always regenerated by the Form Editor.
  71. */
  72. @SuppressWarnings("unchecked")
  73. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  74. private void initComponents()
  75. {
  76. jScrollPane1 = new javax.swing.JScrollPane();
  77. tblSelector = new javax.swing.JTable();
  78. jScrollPane2 = new javax.swing.JScrollPane();
  79. packDesc = new javax.swing.JTextArea();
  80. packTitle = new javax.swing.JLabel();
  81. btnInstall = new javax.swing.JButton();
  82. packStatus = new javax.swing.JLabel();
  83. jLabel1 = new javax.swing.JLabel();
  84. lblVID = new javax.swing.JLabel();
  85. jSeparator1 = new javax.swing.JSeparator();
  86. jSeparator3 = new javax.swing.JSeparator();
  87. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  88. addComponentListener(new java.awt.event.ComponentAdapter()
  89. {
  90. public void componentMoved(java.awt.event.ComponentEvent evt)
  91. {
  92. formComponentMoved(evt);
  93. }
  94. });
  95. tblSelector.setModel(new javax.swing.table.DefaultTableModel(
  96. new Object [][]
  97. {
  98. {null, null, null}
  99. },
  100. new String []
  101. {
  102. "meta:id", "Name", "Status"
  103. }
  104. )
  105. {
  106. boolean[] canEdit = new boolean []
  107. {
  108. false, false, false
  109. };
  110. public boolean isCellEditable(int rowIndex, int columnIndex)
  111. {
  112. return canEdit [columnIndex];
  113. }
  114. });
  115. tblSelector.addMouseListener(new java.awt.event.MouseAdapter()
  116. {
  117. public void mouseClicked(java.awt.event.MouseEvent evt)
  118. {
  119. tblSelectorMouseClicked(evt);
  120. }
  121. });
  122. jScrollPane1.setViewportView(tblSelector);
  123. tblSelector.setColumnModel(new HidableTableColumnModel(tblSelector.getColumnModel()));
  124. if (tblSelector.getColumnModel().getColumnCount() > 0)
  125. {
  126. tblSelector.getColumnModel().getColumn(0).setResizable(false);
  127. tblSelector.getColumnModel().getColumn(0).setPreferredWidth(30);
  128. tblSelector.getColumnModel().getColumn(1).setMinWidth(80);
  129. tblSelector.getColumnModel().getColumn(1).setPreferredWidth(80);
  130. tblSelector.getColumnModel().getColumn(1).setMaxWidth(80);
  131. tblSelector.getColumnModel().getColumn(2).setPreferredWidth(80);
  132. }
  133. packDesc.setColumns(20);
  134. packDesc.setRows(5);
  135. packDesc.addComponentListener(new java.awt.event.ComponentAdapter()
  136. {
  137. public void componentMoved(java.awt.event.ComponentEvent evt)
  138. {
  139. packDescComponentMoved(evt);
  140. }
  141. });
  142. jScrollPane2.setViewportView(packDesc);
  143. packTitle.setText("{PackTitle}");
  144. btnInstall.setText("Installation starten");
  145. btnInstall.addActionListener(new java.awt.event.ActionListener()
  146. {
  147. public void actionPerformed(java.awt.event.ActionEvent evt)
  148. {
  149. btnInstallActionPerformed(evt);
  150. }
  151. });
  152. packStatus.setText("{DepDetails}");
  153. jLabel1.setText("Doppelklicken um Status zu ändern");
  154. lblVID.setText("izSetup 1.0.0 (c) 2012 iZc");
  155. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  156. getContentPane().setLayout(layout);
  157. layout.setHorizontalGroup(
  158. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  159. .addGroup(layout.createSequentialGroup()
  160. .addContainerGap()
  161. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  162. .addGroup(layout.createSequentialGroup()
  163. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  164. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
  165. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
  166. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  167. .addGroup(layout.createSequentialGroup()
  168. .addGap(34, 34, 34)
  169. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  170. .addComponent(packStatus)
  171. .addComponent(packTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE)))
  172. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  173. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 12, Short.MAX_VALUE)
  174. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  175. .addComponent(btnInstall, javax.swing.GroupLayout.PREFERRED_SIZE, 597, javax.swing.GroupLayout.PREFERRED_SIZE)
  176. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 584, javax.swing.GroupLayout.PREFERRED_SIZE))
  177. .addGap(8, 8, 8))))
  178. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  179. .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  180. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  181. .addComponent(lblVID)
  182. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  183. .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 642, javax.swing.GroupLayout.PREFERRED_SIZE)
  184. .addGap(10, 10, 10)))
  185. .addContainerGap())
  186. );
  187. layout.setVerticalGroup(
  188. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  189. .addGroup(layout.createSequentialGroup()
  190. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  191. .addGroup(layout.createSequentialGroup()
  192. .addGap(17, 17, 17)
  193. .addComponent(packStatus))
  194. .addGroup(layout.createSequentialGroup()
  195. .addContainerGap()
  196. .addComponent(jLabel1)))
  197. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  198. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  199. .addGroup(layout.createSequentialGroup()
  200. .addComponent(packTitle)
  201. .addGap(18, 18, 18)
  202. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
  203. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  204. .addComponent(btnInstall, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
  205. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
  206. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
  207. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  208. .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
  209. .addComponent(lblVID, javax.swing.GroupLayout.Alignment.TRAILING)
  210. .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
  211. .addContainerGap())
  212. );
  213. pack();
  214. }// </editor-fold>//GEN-END:initComponents
  215. private void tblSelectorMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_tblSelectorMouseClicked
  216. {//GEN-HEADEREND:event_tblSelectorMouseClicked
  217. int x = tblSelector.getSelectedRow();
  218. String packid=(String)((DefaultTableModel)tblSelector.getModel()).getValueAt(x, 0);
  219. boolean sel = p.packIsScheduled(packid);
  220. if(evt.getClickCount()==2)
  221. {
  222. if(sel==false&&p.packIsInstallable(packid))
  223. {
  224. sel=true;
  225. }
  226. else
  227. {
  228. sel=false;
  229. }
  230. p.setPackInstallState(packid, sel);
  231. }
  232. rebuildTable();
  233. String _packTitle = p.getPackName(packid);
  234. String packDescr = p.getPackDescription(packid);
  235. packTitle.setText(_packTitle);
  236. packDesc.setText(packDescr);
  237. }//GEN-LAST:event_tblSelectorMouseClicked
  238. private String[] handoverqueue;
  239. private void btnInstallActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnInstallActionPerformed
  240. {//GEN-HEADEREND:event_btnInstallActionPerformed
  241. p.createQueue();
  242. handoverqueue = p.getQueue();
  243. new Thread(new Runnable()
  244. {
  245. @Override
  246. @SuppressWarnings("SleepWhileInLoop")
  247. public void run()
  248. {
  249. new InstallProgressGui(handoverqueue).setVisible(true);
  250. }
  251. }).start();
  252. this.setVisible(false);
  253. }//GEN-LAST:event_btnInstallActionPerformed
  254. private void packDescComponentMoved(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_packDescComponentMoved
  255. {//GEN-HEADEREND:event_packDescComponentMoved
  256. //NOP
  257. }//GEN-LAST:event_packDescComponentMoved
  258. private void formComponentMoved(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentMoved
  259. {//GEN-HEADEREND:event_formComponentMoved
  260. Main.topleft_coords_x = getLocation().x;
  261. Main.topleft_coords_y = getLocation().x;
  262. }//GEN-LAST:event_formComponentMoved
  263. private void rebuildTable()
  264. {
  265. String[] tablefill = p.getPackList();
  266. for (int i = 0; i < tablefill.length; i++)
  267. {
  268. String GRP = tablefill[i];
  269. String[] data = GRP.split("\\|");
  270. String packid = data[0];
  271. ((DefaultTableModel)tblSelector.getModel()).setValueAt(data[0], i, 0);
  272. ((DefaultTableModel)tblSelector.getModel()).setValueAt(data[1], i, 1);
  273. ((DefaultTableModel)tblSelector.getModel()).setValueAt("0xFA11", i, 2);
  274. if(p.packIsScheduled(packid))
  275. {
  276. Tools.DebugHelperPrint(packid+"|sched", true, "iZsetup.enableFinerDebug");
  277. ((DefaultTableModel)tblSelector.getModel()).setValueAt("Wird installiert", i, 2);
  278. }
  279. else
  280. {
  281. if(p.packIsInstalled(data[0]))
  282. {
  283. Tools.DebugHelperPrint(packid+"|exis", true, "iZsetup.enableFinerDebug");
  284. ((DefaultTableModel)tblSelector.getModel()).setValueAt("Bereits installiert", i, 2);
  285. }
  286. else
  287. {
  288. if(!p.packIsInstallable(packid))
  289. {
  290. String depName = "";
  291. String depID = p.packDependency(data[0]);
  292. try
  293. {
  294. depName = p.getPackName(depID);
  295. }
  296. catch(Exception e)
  297. {
  298. }
  299. Tools.DebugHelperPrint(packid+"|reqdep:"+depID, true, "iZsetup.enableFinerDebug");
  300. ((DefaultTableModel)tblSelector.getModel()).setValueAt(depName+" benötigt", i, 2);
  301. }
  302. else
  303. {
  304. ((DefaultTableModel)tblSelector.getModel()).setValueAt("Abgewählt", i, 2);
  305. }
  306. }
  307. }
  308. }
  309. }
  310. /**
  311. * @param args the command line arguments
  312. */
  313. public static void main(String args[])
  314. {
  315. /* Set the Nimbus look and feel */
  316. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  317. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  318. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  319. */
  320. try
  321. {
  322. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
  323. {
  324. if ("Nimbus".equals(info.getName()))
  325. {
  326. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  327. break;
  328. }
  329. }
  330. }
  331. catch (ClassNotFoundException ex)
  332. {
  333. java.util.logging.Logger.getLogger(PackagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  334. }
  335. catch (InstantiationException ex)
  336. {
  337. java.util.logging.Logger.getLogger(PackagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  338. }
  339. catch (IllegalAccessException ex)
  340. {
  341. java.util.logging.Logger.getLogger(PackagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  342. }
  343. catch (javax.swing.UnsupportedLookAndFeelException ex)
  344. {
  345. java.util.logging.Logger.getLogger(PackagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  346. }
  347. //</editor-fold>
  348. /* Create and display the form */
  349. java.awt.EventQueue.invokeLater(new Runnable()
  350. {
  351. public void run()
  352. {
  353. new PackagerGUI().setVisible(true);
  354. }
  355. });
  356. }
  357. // Variables declaration - do not modify//GEN-BEGIN:variables
  358. private javax.swing.JButton btnInstall;
  359. private javax.swing.JLabel jLabel1;
  360. private javax.swing.JScrollPane jScrollPane1;
  361. private javax.swing.JScrollPane jScrollPane2;
  362. private javax.swing.JSeparator jSeparator1;
  363. private javax.swing.JSeparator jSeparator3;
  364. private javax.swing.JLabel lblVID;
  365. private javax.swing.JTextArea packDesc;
  366. private javax.swing.JLabel packStatus;
  367. private javax.swing.JLabel packTitle;
  368. private javax.swing.JTable tblSelector;
  369. // End of variables declaration//GEN-END:variables
  370. }