1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 * 28 * Install and Modify Printer implementation 29 */ 30 31 package com.sun.admin.pm.client; 32 33 import java.awt.*; 34 import java.awt.event.*; 35 import java.util.Vector; 36 import javax.swing.JPanel; 37 import javax.swing.*; 38 import javax.swing.JTable; 39 import javax.swing.ListSelectionModel; 40 import javax.swing.event.ListSelectionListener; 41 import javax.swing.event.ListSelectionEvent; 42 import javax.swing.table.AbstractTableModel; 43 44 import com.sun.admin.pm.server.*; 45 46 47 /* 48 * Window for Edit -> Install Printer 49 */ 50 51 public class pmInstallPrinter extends pmInstallScreen { 52 53 int action; 54 pmTop myTop; 55 pmFrame frame; 56 JScrollPane scrollPane; 57 String printer = null; 58 String server = null; 59 String description = null; 60 String port = null; 61 String ptype = null; 62 String fcontents = null; 63 String make = null; 64 String model = null; 65 String ppd = null; 66 String ppdfile = null; 67 String oldmake = new String("oldmake"); 68 String oldmodel = new String("oldmodel"); 69 String faultn = null; 70 String banner = null; 71 String destination = null; 72 String protocol = null; 73 String useraccesslist[] = null; 74 String oldptype = null; 75 String olddevice = null; 76 Printer workingPrinter; 77 78 JList accessList; 79 JScrollPane ascrollPane; 80 accessListModel accessModel; 81 82 String helpTag = null; 83 84 String cmdLog = null; 85 String errorLog = null; 86 String warnLog = null; 87 88 String actionName = null; 89 90 // where to place initial focus 91 Component defaultComponent = null; 92 93 boolean usePPD; 94 boolean useLocalhost; 95 pmInstallPrinter(pmTop myTop, int action)96 public pmInstallPrinter(pmTop myTop, int action) throws pmGuiException { 97 boolean failed = false; 98 boolean cacheerr = false; 99 boolean ppdincacheerr = false; 100 101 this.myTop = myTop; 102 this.action = action; 103 workingPrinter = new Printer(myTop.ns); 104 105 usePPD = myTop.getUsePPD(); 106 useLocalhost = myTop.getUseLocalhost(); 107 108 switch (action) { 109 110 case Constants.ADDLOCAL: 111 112 Debug.message("CLNT:pmInstPr: ADD LOCAL"); 113 frame = new pmFrame( 114 pmUtility.getResource("SPM:New.Attached.Printer")); 115 if (pmMisc.isppdCachefile() && usePPD) { 116 helpTag = "InstallLocalPPD"; 117 } else { 118 helpTag = "InstallLocal"; 119 } 120 actionName = 121 pmUtility.getResource("New.Attached.Printer"); 122 break; 123 124 case Constants.ADDNETWORK: 125 126 Debug.message("CLNT:pmInstPr: ADD NETWORK"); 127 frame = new pmFrame( 128 pmUtility.getResource("SPM:New.Network.Printer")); 129 if ((pmMisc.isppdCachefile()) && (usePPD)) { 130 helpTag = "InstallNetworkPPD"; 131 } else 132 helpTag = "InstallNetwork"; 133 actionName = pmUtility.getResource("New.Network.Printer"); 134 break; 135 136 case Constants.MODIFYATTACHED: 137 138 Debug.message("CLNT:pmInstPr: MODIFY ATTACHED"); 139 frame = new pmFrame( 140 pmUtility.getResource("SPM:Modify.Printer.Properties")); 141 workingPrinter.setPrinterName(myTop.selectedPrinter); 142 143 failed = false; 144 try { 145 workingPrinter.getPrinterDetails(); 146 147 } catch (pmNeedPPDCacheException e) { 148 cacheerr = true; 149 Debug.message("CLNT:pmInstPr:ModifyAttached caught: " + e); 150 151 } catch (pmCacheMissingPPDException e) { 152 ppdincacheerr = true; 153 Debug.message("CLNT:pmInstPr:ModifyAttached caught: " + e); 154 155 } catch (Exception e) { 156 failed = true; 157 Debug.message("CLNT:pmInsPr:ModifyAttached caught:" + e); 158 } 159 160 gatherLogs(workingPrinter); 161 162 if (cacheerr) { 163 pmMessageDialog m = new pmMessageDialog( 164 frame, 165 pmUtility.getResource("Error"), 166 pmUtility.getResource( 167 "Cannot.modify.this.queue;ppdcache.file.missing.")); 168 169 m.setVisible(true); 170 171 throw new pmGuiException("No ppdcache file"); 172 } 173 174 if (ppdincacheerr) { 175 pmMessageDialog m = new pmMessageDialog( 176 frame, 177 pmUtility.getResource("Error"), 178 pmUtility.getResource( 179 "Cannot.modify.this.queue;PPD.file.not.in.ppdcache.")); 180 181 m.setVisible(true); 182 183 throw new pmGuiException("PPD file not in ppdcache"); 184 } 185 186 if (failed) { 187 // error popup? 188 // throw something? 189 } 190 191 pmCalls.debugShowPrinter(workingPrinter); 192 dumpLogs("ModifyAttached()"); 193 194 if (workingPrinter.getPPD() != null) 195 helpTag = "ModifyPPD"; 196 else 197 helpTag = "Modify"; 198 199 // helpTag = "ModifyAttached"; 200 201 actionName = pmUtility.getResource("Modify.Printer.Properties"); 202 break; 203 204 case Constants.MODIFYNETWORK: 205 206 Debug.message("CLNT:pmInstPr: MODIFY NETWORK"); 207 frame = new pmFrame( 208 pmUtility.getResource("SPM:Modify.Printer.Properties")); 209 workingPrinter.setPrinterName(myTop.selectedPrinter); 210 211 workingPrinter.setPrinterName(myTop.selectedPrinter); 212 failed = false; 213 214 try { 215 workingPrinter.getPrinterDetails(); 216 } catch (Exception e) { 217 failed = true; 218 Debug.message("CLNT:pmInstPr:ModifyNetwork caught " + e); 219 } 220 221 gatherLogs(workingPrinter); 222 223 if (failed) { 224 // error popup? 225 // throw new pmGuiException(); 226 } 227 228 pmCalls.debugShowPrinter(workingPrinter); 229 dumpLogs("ModifyNetwork()"); 230 231 if (workingPrinter.getPPD() != null) 232 helpTag = "ModifyPPD"; 233 else 234 helpTag = "Modify"; 235 // helpTag = "ModifyNetwork"; 236 237 actionName = pmUtility.getResource("Modify.Printer.Properties"); 238 239 break; 240 241 case Constants.MODIFYREMOTE: 242 Debug.message("CLNT:pmInstPr: MODIFY REMOTE"); 243 frame = new pmFrame( 244 pmUtility.getResource("SPM:Modify.Printer.Properties")); 245 246 workingPrinter.setPrinterName(myTop.selectedPrinter); 247 248 failed = false; 249 try { 250 workingPrinter.getPrinterDetails(); 251 } catch (Exception e) { 252 failed = true; 253 Debug.warning("CLNT:pmInstPr:ModifyRemote caught " + e); 254 } 255 gatherLogs(workingPrinter); 256 257 if (failed) { 258 // error popup? 259 // throw something? 260 } 261 262 263 if (workingPrinter.getPPD() != null) 264 helpTag = "ModifyPPD"; 265 else 266 helpTag = "Modify"; 267 // helpTag = "ModifyRemote"; 268 269 actionName = pmUtility.getResource("Modify.Printer.Properties"); 270 break; 271 272 } 273 274 // ensure that pmButton hashtable gets cleaned up 275 frame.setClearButtonsOnClose(true); 276 277 setLayout(new BorderLayout()); 278 279 // Build the Screen 280 northPanel(); 281 if (action != Constants.MODIFYREMOTE) { 282 centerPanel(); 283 } 284 285 southPanel(); 286 287 // default button is always OK, for now... 288 // frame.getRootPane().setDefaultButton (okButton); 289 // okButton.setAsDefaultButton (); 290 291 // handle Esc as cancel 292 this.registerKeyboardAction(new ActionListener() { 293 public void actionPerformed(ActionEvent e) { 294 Debug.message("CLNT: default cancel action"); 295 actioncancelButton(); 296 }}, 297 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), 298 JComponent.WHEN_IN_FOCUSED_WINDOW); 299 300 if (action == Constants.ADDLOCAL || action == Constants.ADDNETWORK) { 301 defaultComponent = pnameText; 302 } else { 303 defaultComponent = descText; 304 } 305 306 frame.setDefaultComponent(defaultComponent); 307 308 defaultComponent.addFocusListener(new FocusListener() { 309 public void focusGained(FocusEvent e) { 310 Debug.info("\ncomponent focus gained: " + e); 311 } 312 public void focusLost(FocusEvent e) { 313 Debug.info("\ncomponent focus lost: " + e); 314 } 315 }); 316 317 } 318 319 320 public class accessListModel extends AbstractListModel { 321 int numColumns; 322 Vector data; 323 Vector access = new Vector(1, 1); 324 accessListModel()325 public accessListModel() { 326 numColumns = getColumnCount(); 327 } 328 addaccessList(String data[])329 public void addaccessList(String data[]) { 330 331 for (int i = 0; i < data.length; i++) { 332 access.addElement(data[i]); 333 334 } 335 } 336 addaccessList(String data)337 public void addaccessList(String data) { 338 access.addElement(data); 339 } 340 isduplicate(String d)341 public boolean isduplicate(String d) { 342 if (access == null) 343 return false; 344 else 345 return access.contains(d); 346 } 347 removeRow(int row)348 public void removeRow(int row) { 349 access.removeElementAt(row); 350 } 351 removeListEntries()352 public void removeListEntries() { 353 access.removeAllElements(); 354 } 355 getRowCount()356 public int getRowCount() { 357 return access.size(); 358 } 359 getSize()360 public int getSize() { 361 return access.size(); 362 } 363 getColumnCount()364 public int getColumnCount() { 365 return 1; 366 } 367 addRow(Vector row)368 public void addRow(Vector row) { 369 access.addElement(row); 370 } 371 getValueAt(int row)372 public Object getValueAt(int row) { 373 return access.elementAt(row); 374 } 375 getElementAt(int row)376 public Object getElementAt(int row) { 377 return access.elementAt(row); 378 } 379 getValueAt(int row, int col)380 public Object getValueAt(int row, int col) { 381 return access.elementAt(row); 382 } 383 setValueAt(String value, int row)384 public void setValueAt(String value, int row) { 385 access.setElementAt(value, row); 386 } 387 getAccessList()388 public Vector getAccessList() { 389 return access; 390 } 391 accesstoArray(String[] target)392 public void accesstoArray(String[] target) { 393 access.copyInto(target); 394 } 395 396 } 397 centerPanel()398 public void centerPanel() { 399 JPanel center = new JPanel(); 400 401 accessModel = new accessListModel(); 402 accessList = new JList(accessModel); 403 accessList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 404 405 406 center.setLayout(new GridBagLayout()); 407 GridBagConstraints c = new GridBagConstraints(); 408 409 ListSelectionModel rowSelectModel = accessList.getSelectionModel(); 410 rowSelectModel.addListSelectionListener(new ListSelectionListener() { 411 public void valueChanged(ListSelectionEvent e) { 412 ListSelectionModel accessSM = 413 (ListSelectionModel)e.getSource(); 414 } 415 }); 416 417 c.insets = new Insets(5, 5, 5, 5); 418 419 // Create the label 420 c.gridx = 0; 421 c.gridy = 0; 422 labelConstraints(c); 423 center.add(new JLabel 424 (pmUtility.getResource("User.Access.List:")), c); 425 426 // Create User Access List 427 String[] tmp = workingPrinter.getUserAllowList(); 428 429 430 if (tmp == null) { 431 accessModel.addaccessList("all"); 432 } else { 433 accessModel.addaccessList(tmp); 434 } 435 436 ascrollPane = new JScrollPane(accessList); 437 438 c.gridwidth = 2; 439 c.gridx = 1; 440 c.weightx = c.weighty = 1.0; 441 c.fill = GridBagConstraints.BOTH; 442 center.add(ascrollPane, c); 443 444 // Create Textfield 445 c.gridx = 1; 446 c.gridy = 1; 447 c.ipadx = 15; 448 c.fill = GridBagConstraints.HORIZONTAL; 449 c.anchor = GridBagConstraints.WEST; 450 c.weightx = c.weighty = 1.0; 451 userText = new pmTextField(25); 452 center.add(userText, c); 453 454 // Add the Add/Delete Buttons 455 c.gridx = 1; 456 c.gridy = 2; 457 458 adButtons(c); 459 460 c.gridwidth = 1; 461 center.add(addButton, c); 462 463 c.gridx = 2; 464 center.add(deleteButton, c); 465 466 add("Center", center); 467 468 } 469 northPanel()470 public void northPanel() { 471 JPanel north = new JPanel(); 472 north.setLayout(new GridBagLayout()); 473 GridBagConstraints c = new GridBagConstraints(); 474 475 northPanelConstraints(c); 476 477 // Define the constraints and create the labels 478 479 // All Add/Modify 480 labelConstraints(c); 481 c.gridx = 0; 482 c.gridy = 0; 483 printernameLabel(north, c); 484 c.gridy++; 485 servernameLabel(north, c); 486 c.gridy++; 487 descriptionLabel(north, c); 488 c.gridy++; 489 490 // Add printers, modify local 491 if (action != Constants.MODIFYREMOTE) { 492 493 if ((action == Constants.ADDLOCAL) || 494 (action == Constants.MODIFYATTACHED)) { 495 printerportLabel(north, c); 496 c.gridy++; 497 } 498 499 if ((action == Constants.ADDLOCAL) || 500 (action == Constants.ADDNETWORK)) { 501 if ((pmMisc.isppdCachefile()) && (usePPD)) { 502 printermakeLabel(north, c); 503 c.gridy++; 504 printermodelsLabel(north, c); 505 c.gridy++; 506 ppdcontentsLabel(north, c); 507 } else { 508 printertypeLabel(north, c); 509 c.gridy++; 510 filecontentsLabel(north, c); 511 } 512 } 513 514 if ((action == Constants.MODIFYATTACHED) || 515 (action == Constants.MODIFYNETWORK)) { 516 517 // Show make/model/ppd or type/contents 518 519 if (workingPrinter.getPPD() != null) { 520 521 printermakeLabel(north, c); 522 c.gridy++; 523 printermodelsLabel(north, c); 524 c.gridy++; 525 ppdcontentsLabel(north, c); 526 } else { 527 printertypeLabel(north, c); 528 c.gridy++; 529 filecontentsLabel(north, c); 530 } 531 } 532 533 c.gridy++; 534 faultnotLabel(north, c); 535 c.gridy++; 536 537 if (action == Constants.ADDNETWORK || 538 action == Constants.MODIFYNETWORK) { 539 destinationLabel(north, c); 540 c.gridy++; 541 protocolLabel(north, c); 542 c.gridy++; 543 } 544 545 optionsLabel(north, c); 546 c.gridy++; 547 bannerLabel(north, c); 548 } else { 549 optionLabel(north, c); 550 } 551 552 // Define the constraints and create the fields 553 554 // Add printers 555 c.gridx = 1; 556 c.gridy = 0; 557 558 // Printer Name and Server Name 559 if ((action == Constants.ADDLOCAL) || 560 (action == Constants.ADDNETWORK)) { 561 562 TextFieldConstraints(c); 563 printernameTextField(north, c); 564 c.gridy++; 565 labelConstraints(c); 566 try { 567 north.add(new JLabel( 568 myTop.host.getLocalHostName()), c); 569 } catch (Exception e) { 570 Debug.warning( 571 "CLNT:pmInstPr:getLocalHostName exception " + e); 572 north.add(new JLabel(" "), c); 573 } 574 c.gridy++; 575 } else { 576 labelConstraints(c); 577 north.add(new JLabel(myTop.selectedPrinter), c); 578 c.gridy++; 579 labelConstraints(c); 580 north.add(new JLabel(myTop.selprinterServer), c); 581 c.gridy++; 582 } 583 584 // Description 585 TextFieldConstraints(c); 586 descriptionField(north, c); 587 if (action == Constants.MODIFYATTACHED || 588 action == Constants.MODIFYNETWORK || 589 action == Constants.MODIFYREMOTE) { 590 if (workingPrinter.getComment() != null) 591 descText.setText(workingPrinter.getComment()); 592 } 593 c.gridy++; 594 595 if (action != Constants.MODIFYREMOTE) { 596 if (action == Constants.ADDLOCAL) { 597 comboboxConstraints(c); 598 printerportField(north, c); 599 c.gridy++; 600 601 } else if (action == Constants.MODIFYATTACHED) { 602 labelConstraints(c); 603 north.add(new JLabel(workingPrinter.getDevice()), c); 604 c.gridy++; 605 } 606 607 comboboxConstraints(c); 608 609 if ((action == Constants.ADDLOCAL) || 610 (action == Constants.ADDNETWORK)) { 611 if ((pmMisc.isppdCachefile()) && (usePPD)) { 612 printermakeField(north, c); 613 c.gridy++; 614 printermodelsField(north, c); 615 c.gridy++; 616 ppdcontentsField(north, c); 617 } else { 618 printertypeField(north, c); 619 c.gridy++; 620 filecontentsField(north, c); 621 } 622 } 623 624 if ((action == Constants.MODIFYATTACHED) || 625 (action == Constants.MODIFYNETWORK)) { 626 627 if (workingPrinter.getPPD() != null) { 628 629 printermakeField(north, c); 630 c.gridy++; 631 printermodelsField(north, c); 632 c.gridy++; 633 ppdcontentsField(north, c); 634 635 setMake(); 636 setModel(); 637 setPPD(); 638 639 } else { 640 // display with printer type and file contents 641 642 printertypeField(north, c); 643 setPrinterType(); 644 645 c.gridy++; 646 647 filecontentsField(north, c); 648 setType(); 649 } 650 } 651 652 c.gridy++; 653 654 faultnotField(north, c); 655 if (action == Constants.MODIFYATTACHED || 656 action == Constants.MODIFYNETWORK) { 657 658 setFault(); 659 } 660 c.gridy++; 661 662 if (action == Constants.ADDNETWORK || 663 action == Constants.MODIFYNETWORK) { 664 665 TextFieldConstraints(c); 666 destinationField(north, c); 667 c.gridy++; 668 comboboxConstraints(c); 669 protocolField(north, c); 670 c.gridy++; 671 if (action == Constants.MODIFYNETWORK) 672 setNetworkInfo(); 673 } 674 675 optionsConstraints(c); 676 optionsFields(north, c); 677 if (action == Constants.MODIFYATTACHED || 678 action == Constants.MODIFYNETWORK) { 679 if (workingPrinter.getIsDefaultPrinter()) { 680 defaultp.doClick(); 681 } 682 setBanner(); 683 } 684 } else { 685 optionsConstraints(c); 686 defaultoptionField(north, c); 687 if (workingPrinter.getIsDefaultPrinter()) { 688 defaultp.doClick(); 689 } 690 } 691 692 add("North", north); 693 } 694 setNetworkInfo()695 public void setNetworkInfo() { 696 String p = workingPrinter.getProtocol(); 697 698 if (p != null) { 699 if (p.equals("bsd")) 700 protocolCombo.setSelectedItem("BSD"); 701 else if (p.equals("tcp")) 702 protocolCombo.setSelectedItem("TCP"); 703 else if (p.equals("uri")) 704 protocolCombo.setSelectedItem("URI"); 705 706 } 707 708 if (destText != null) 709 destText.setText(workingPrinter.getDestination()); 710 } 711 setMake()712 public void setMake() { 713 String make = workingPrinter.getMake(); 714 if (make != null) { 715 makeCombo.setSelectedItem(make); 716 } 717 } setModel()718 public void setModel() { 719 String model = workingPrinter.getModel(); 720 if (model != null) 721 modelCombo.setSelectedItem(model); 722 } setPPD()723 public void setPPD() { 724 String ppd = workingPrinter.getPPD(); 725 if (ppd != null) 726 ppdCombo.setSelectedItem(ppd); 727 } 728 setFault()729 public void setFault() { 730 String fault = workingPrinter.getNotify(); 731 732 if (fault == null || fault == "none") 733 faultCombo.setSelectedItem( 734 pmUtility.getResource("None")); 735 736 else if (fault.equals("write")) 737 faultCombo.setSelectedItem( 738 pmUtility.getResource("Write.to.Superuser")); 739 740 else if (fault.equals("mail")) 741 faultCombo.setSelectedItem( 742 pmUtility.getResource("Mail.to.Superuser")); 743 else { 744 faultCombo.addItem(fault); 745 faultCombo.setSelectedItem(fault); 746 } 747 } 748 setBanner()749 public void setBanner() { 750 String banner = workingPrinter.getBanner(); 751 752 if (banner == null) 753 bannerCombo.setSelectedItem( 754 pmUtility.getResource("Always.Print.Banner")); 755 756 else if (banner.equals("never")) 757 bannerCombo.setSelectedItem( 758 pmUtility.getResource("Never.Print.Banner")); 759 760 else if (banner.equals("always")) 761 bannerCombo.setSelectedItem( 762 pmUtility.getResource("Always.Print.Banner")); 763 764 else if (banner.equals("optional")) 765 bannerCombo.setSelectedItem( 766 pmUtility.getResource("User.Selectable.Default.On")); 767 } 768 setType()769 public void setType() { 770 // lpadmin can combine things like: simple,any ... 771 772 String filedata[] = workingPrinter.getFileContents(); 773 String filecontents = new String(); 774 775 if (filedata == null) { 776 fileCombo.setSelectedItem( 777 pmUtility.getResource("None")); 778 } else { 779 for (int i = 0; i < filedata.length; i++) { 780 if (i > 0 && filedata[i] != null) 781 filecontents = filecontents.concat(","); 782 783 filecontents = filecontents.concat(filedata[i]); 784 } 785 Debug.message("CLNT:pmInstPr:setType: filecontents = " + 786 filecontents); 787 788 if (filecontents.equals("postscript")) { 789 fileCombo.setSelectedItem(pmUtility.getResource( 790 "PostScript")); 791 } else if (filecontents.equals("application/postscript")) { 792 fileCombo.setSelectedItem(pmUtility.getResource( 793 "PostScript")); 794 795 } else if (filecontents.equals("simple")) { 796 fileCombo.setSelectedItem(pmUtility.getResource("ASCII")); 797 } else if (filecontents.equals("text/plain")) { 798 fileCombo.setSelectedItem(pmUtility.getResource("ASCII")); 799 800 } else if (filecontents.equals("postscript,simple")) { 801 fileCombo.setSelectedItem(pmUtility.getResource( 802 "Both.PostScript.and.ASCII")); 803 } else if (filecontents.equals("simple,postscript")) { 804 fileCombo.setSelectedItem(pmUtility.getResource( 805 "Both.PostScript.and.ASCII")); 806 } else if (filecontents.equals( 807 "text/plain,application/postscript")) { 808 fileCombo.setSelectedItem(pmUtility.getResource( 809 "Both.PostScript.and.ASCII")); 810 811 } else if (filecontents.equals("none")) { 812 fileCombo.setSelectedItem( 813 pmUtility.getResource("None")); 814 } else if (filecontents.equals("any")) { 815 fileCombo.setSelectedItem( 816 pmUtility.getResource("Any")); 817 } else if (filecontents.equals("application/octet-stream")) { 818 fileCombo.setSelectedItem( 819 pmUtility.getResource("Any")); 820 } else { 821 Debug.message( 822 "CLNT:pmInstPr:setType()unknown file contents type"); 823 fileCombo.addItem(filecontents); 824 fileCombo.setSelectedItem(filecontents); 825 } 826 } 827 } 828 setPrinterType()829 public void setPrinterType() { 830 int x = 0; 831 String type = workingPrinter.getPrinterType(); 832 Debug.message( 833 "CLNT:pmInstPrsetPrinterType(): printer type is " + type); 834 835 if (type == null) 836 return; 837 838 if (type.equals("PS")) { 839 typeCombo.setSelectedItem("PostScript"); 840 } else if (type.equals("hplaser")) { 841 typeCombo.setSelectedItem("HP Printer"); 842 } else if (type.equals("PSR")) { 843 typeCombo.setSelectedItem("Reverse PostScript"); 844 } else if (type.equals("epson2500")) { 845 typeCombo.setSelectedItem("Epson 2500"); 846 } else if (type.equals("ibmproprinter")) { 847 typeCombo.setSelectedItem("IBM ProPrinter"); 848 } else if (type.equals("qume5")) { 849 typeCombo.setSelectedItem("Qume Sprint 5"); 850 } else if (type.equals("daisy")) { 851 typeCombo.setSelectedItem("Daisy"); 852 } else if (type.equals("diablo")) { 853 typeCombo.setSelectedItem("Diablo"); 854 } else if (type.equals("datagraphix")) { 855 typeCombo.setSelectedItem("Datagraphix"); 856 } else if (type.equals("la100")) { 857 typeCombo.setSelectedItem("DEC LA100"); 858 } else if (type.equals("ln03")) { 859 typeCombo.setSelectedItem("DEC LN03"); 860 } else if (type.equals("decwriter")) { 861 typeCombo.setSelectedItem("Dec Writer"); 862 } else if (type.equals("ti800")) { 863 typeCombo.setSelectedItem("Texas Instruments 800"); 864 } else { 865 typeCombo.addItem(type); 866 typeCombo.setSelectedItem(type); 867 Debug.message( 868 "CLNT:pmInstPr:setPrinterType(): user defined type " + 869 type); 870 } 871 872 } 873 getMakeModelPPD()874 public void getMakeModelPPD() throws pmGuiException { 875 if (pmMisc.isppdCachefile()) { 876 getMake(); 877 878 model = (String)modelCombo.getSelectedItem(); 879 ppd = (String)ppdCombo.getSelectedItem(); 880 } 881 } 882 getTypeContents()883 public void getTypeContents() throws pmGuiException { 884 ptype = (String)typeCombo.getSelectedItem(); 885 fcontents = (String)fileCombo.getSelectedItem(); 886 } 887 getFault()888 public void getFault() throws pmGuiException { 889 faultn = (String)faultCombo.getSelectedItem(); 890 } 891 getBanner()892 public void getBanner() throws pmGuiException { 893 banner = (String)bannerCombo.getSelectedItem(); 894 } 895 getPrinterServer()896 public void getPrinterServer() throws pmGuiException { 897 898 // Printer Name is a required field. 899 printer = pnameText.getText(); 900 if (printer.equals("")) { 901 pnameText.requestFocus(); 902 throw new pmIncompleteFormException( 903 pmUtility.getResource("Printer.name.required.")); 904 } 905 906 if (!Valid.localPrinterName(printer)) { 907 pnameText.requestFocus(); 908 throw new pmIncompleteFormException( 909 pmUtility.getResource("Printer.name.invalid.")); 910 } 911 912 server = null; 913 try { 914 if ((useLocalhost)) 915 server = "localhost"; 916 else 917 server = myTop.host.getLocalHostName(); 918 } catch (Exception e) { 919 Debug.warning( 920 "CLNT:pmInstPr:getLocalHostName exception " + e); 921 } 922 923 Debug.message( 924 "CLNT:pmInstPr:getPrinterServer(): printer is: " + printer); 925 Debug.message( 926 "CLNT:pmInstPr:getPrinterServer(): server is: " + server); 927 928 } 929 getPort()930 public void getPort() throws pmGuiException { 931 port = (String)portCombo.getSelectedItem(); 932 if (port.equals(pmUtility.getResource("Not.Selected"))) { 933 portCombo.requestFocus(); 934 throw new pmIncompleteFormException 935 (pmUtility.getResource( 936 "Printer.Port.Selection.required")); 937 } 938 Debug.message("CLNT:pmInstPr:getPort(): port is: " + port); 939 } 940 getMake()941 public void getMake() throws pmGuiException { 942 make = (String)makeCombo.getSelectedItem(); 943 if (make.equals(pmUtility.getResource("Not.Selected"))) { 944 makeCombo.requestFocus(); 945 throw new pmIncompleteFormException 946 (pmUtility.getResource( 947 "Printer.Make.Selection.required")); 948 } 949 Debug.message("CLNT:pmInstPr:getMake(): make is: " + make); 950 } 951 getNetworkInfo()952 public void getNetworkInfo() throws pmIncompleteFormException { 953 destination = destText.getText(); 954 if (destination.equals("")) { 955 destText.requestFocus(); 956 throw new pmIncompleteFormException( 957 pmUtility.getResource("Destination.required.")); 958 } 959 960 if (!Valid.destination(destination)) { 961 destText.requestFocus(); 962 throw new pmIncompleteFormException( 963 pmUtility.getResource("Destination.invalid.")); 964 } 965 966 protocol = (String)protocolCombo.getSelectedItem(); 967 port = new String("/dev/null"); 968 Debug.message( 969 "CLNT:pmInstPr:getNetworkInfo(): destination is: " + 970 destination); 971 Debug.message( 972 "CLNT:pmInstPr:getNetworkInfo(): protocol is: " + protocol); 973 } 974 getDescription()975 public void getDescription() { 976 977 String messy; 978 979 messy = descText.getText(); 980 description = messy.trim(); 981 Debug.message( 982 "CLNT:pmInstPr:getDescription():description: " + "<" + 983 description + ">"); 984 985 if (workingPrinter.getComment() == null && description.equals("")) 986 description = null; 987 988 } 989 getUserAccess()990 public void getUserAccess() { 991 992 if (accessModel.getRowCount() != 0) { 993 useraccesslist = new String[accessModel.getRowCount()]; 994 accessModel.accesstoArray(useraccesslist); 995 } else { 996 useraccesslist = null; 997 } 998 } 999 gui2lpptype(String t)1000 public String gui2lpptype(String t) { 1001 String lp; 1002 1003 if (t != null) { 1004 if (t.equals("PostScript")) 1005 lp = new String("PS"); 1006 else if (t.equals("HP Printer")) 1007 lp = new String("hplaser"); 1008 else if (t.equals("Reverse PostScript")) 1009 lp = new String("PSR"); 1010 else if (t.equals("Epson 2500")) 1011 lp = new String("epson2500"); 1012 else if (t.equals("IBM ProPrinter")) 1013 lp = new String("ibmproprinter"); 1014 else if (t.equals("Qume Sprint 5")) 1015 lp = new String("qume5"); 1016 else if (t.equals("Daisy")) 1017 lp = new String("daisy"); 1018 else if (t.equals("Diablo")) 1019 lp = new String("diablo"); 1020 else if (t.equals("Datagraphix")) 1021 lp = new String("datagraphix"); 1022 else if (t.equals("DEC LA100")) 1023 lp = new String("la100"); 1024 else if (t.equals("DEC LN03")) 1025 lp = new String("ln03"); 1026 else if (t.equals("Dec Writer")) 1027 lp = new String("decwriter"); 1028 else if (t.equals("Texas Instruments 800")) 1029 lp = new String("ti800"); 1030 else { 1031 Debug.message( 1032 "CLNT:pmIns:gui2lptype: printer type unknown: " + t); 1033 lp = new String(t); 1034 } 1035 } else { 1036 Debug.message("CLNT:pmInstPr:gui2lptype: input printer type null"); 1037 lp = new String(""); 1038 } 1039 1040 return lp; 1041 } 1042 gui2lpfcontents(String f)1043 public String[] gui2lpfcontents(String f) { 1044 1045 String[] lp = null; 1046 1047 if (f != null) { 1048 if (f.equals(pmUtility.getResource("PostScript"))) { 1049 lp = new String[1]; 1050 lp[0] = new String("postscript"); 1051 } else if (f.equals(pmUtility.getResource("ASCII"))) { 1052 lp = new String[1]; 1053 lp[0] = new String("simple"); 1054 } else if (f.equals(pmUtility.getResource( 1055 "Both.PostScript.and.ASCII"))) { 1056 lp = new String[2]; 1057 lp[0] = new String("simple"); 1058 lp[1] = new String("postscript"); 1059 } else if (f.equals(pmUtility.getResource("Any"))) { 1060 lp = new String[1]; 1061 lp[0] = new String("any"); 1062 } else if (f.equals(pmUtility.getResource("None"))) { 1063 lp = new String[1]; 1064 lp[0] = new String("none"); 1065 } 1066 } else { 1067 Debug.message( 1068 "CLNT:pmInstPr:gui2lpfcontents(): input string null"); 1069 } 1070 1071 return lp; 1072 } 1073 gui2lpfaultn(String n)1074 public String gui2lpfaultn(String n) { 1075 String lp = null; 1076 if (n != null) { 1077 if (n.equals(pmUtility.getResource("Write.to.Superuser"))) 1078 lp = new String("write"); 1079 else if (n.equals(pmUtility.getResource("Mail.to.Superuser"))) 1080 lp = new String("mail"); 1081 else if (n.equals(pmUtility.getResource("None"))) 1082 lp = new String("none"); 1083 1084 } else { 1085 Debug.message( 1086 "CLNT:pmInstPr:gui2lpfaultn():input faultnotify null"); 1087 } 1088 return lp; 1089 } 1090 gui2lpprotocol(String p)1091 public String gui2lpprotocol(String p) { 1092 String lp = null; 1093 if (p.equals("TCP")) 1094 lp = new String("tcp"); 1095 else if (p.equals("BSD")) 1096 lp = new String("bsd"); 1097 else if (p.equals("URI")) 1098 lp = new String("uri"); 1099 else { 1100 Debug.message( 1101 "CLNT:pmInstPr:gui2lpprotocol: protocol is empty"); 1102 } 1103 return lp; 1104 } 1105 gui2lpbanner(String p)1106 public String gui2lpbanner(String p) { 1107 String lp = null; 1108 if (p.equals(pmUtility.getResource("Always.Print.Banner"))) 1109 lp = new String("always"); 1110 else if (p.equals(pmUtility.getResource("Never.Print.Banner"))) 1111 lp = new String("never"); 1112 else if (p.equals(pmUtility.getResource("User.Selectable.Default.On"))) 1113 lp = new String("optional"); 1114 else { 1115 Debug.message( 1116 "CLNT:pmInstPr:gui2lpbanner(): banner is empty"); 1117 } 1118 1119 if (lp != null) 1120 Debug.message( 1121 "CLNT:pmInstPr:gui2lpbanner(): banner is " + lp); 1122 return lp; 1123 1124 } 1125 updatePrinter()1126 public void updatePrinter() { 1127 if (workingPrinter != null) { 1128 if (printer != null) 1129 workingPrinter.setPrinterName(printer); 1130 if (server != null) { 1131 workingPrinter.setPrintServer(server); 1132 } 1133 if (description != null) 1134 workingPrinter.setComment(description); 1135 if ((port != null) && 1136 (!port.equals(pmUtility.getResource("Not.Selected")))) 1137 workingPrinter.setDevice(port); 1138 if (make != null) { 1139 workingPrinter.setMake(make); 1140 } 1141 if (model != null) { 1142 workingPrinter.setModel(model); 1143 } 1144 if (ppd != null) { 1145 workingPrinter.setPPD(ppd); 1146 } 1147 1148 workingPrinter.setUsePPD(usePPD); 1149 1150 if (ptype != null) 1151 workingPrinter.setPrinterType(gui2lpptype(ptype)); 1152 if (fcontents != null) 1153 workingPrinter.setFileContents(gui2lpfcontents(fcontents)); 1154 if (faultn != null) 1155 workingPrinter.setNotify(gui2lpfaultn(faultn)); 1156 if (destination != null) 1157 workingPrinter.setDestination(destination); 1158 if (protocol != null) 1159 workingPrinter.setProtocol(gui2lpprotocol(protocol)); 1160 if (useraccesslist != null) 1161 workingPrinter.setUserAllowList(useraccesslist); 1162 else { 1163 String[] a = new String[1]; 1164 a[0] = new String("none"); 1165 workingPrinter.setUserAllowList(a); 1166 } 1167 1168 if (defaultp != null) 1169 workingPrinter.setIsDefaultPrinter(defaultp.isSelected()); 1170 1171 if (banner != null) 1172 workingPrinter.setBanner(gui2lpbanner(banner)); 1173 1174 } else { 1175 Debug.warning( 1176 "CLNT:pmInstPr:updatePrinter(): workingPrinter null"); 1177 } 1178 } 1179 1180 gatherLogs(Printer p)1181 void gatherLogs(Printer p) { 1182 cmdLog = p.getCmdLog(); 1183 errorLog = p.getErrorLog(); 1184 warnLog = p.getWarnLog(); 1185 } 1186 1187 dumpLogs(String who)1188 void dumpLogs(String who) { 1189 Debug.message(who); 1190 Debug.message(who + " command: " + cmdLog); 1191 Debug.message(who + " warnings: " + warnLog); 1192 Debug.message(who + " errors: " + errorLog); 1193 } 1194 1195 doAddLocal()1196 public void doAddLocal() throws pmGuiException { 1197 1198 try { 1199 getPrinterServer(); 1200 getDescription(); 1201 getPort(); 1202 if ((pmMisc.isppdCachefile()) && (usePPD)) { 1203 getMakeModelPPD(); 1204 } else { 1205 getTypeContents(); 1206 } 1207 getFault(); 1208 getBanner(); 1209 getUserAccess(); 1210 updatePrinter(); 1211 1212 } catch (pmIncompleteFormException ie) { 1213 throw new pmIncompleteFormException(ie.getMessage()); 1214 } 1215 1216 1217 boolean exist; 1218 boolean failed = false; 1219 1220 // exists could throw an exception from the underyling cmds... 1221 try { 1222 exist = PrinterUtil.exists(printer, myTop.ns); 1223 } catch (Exception e) { 1224 throw new pmGuiException(); 1225 } 1226 1227 if (exist) { 1228 throw new pmPrinterExistsException(); 1229 } 1230 1231 try { 1232 workingPrinter.addLocalPrinter(); 1233 } catch (Exception e) { 1234 failed = true; 1235 } finally { 1236 gatherLogs(workingPrinter); 1237 pmCalls.debugShowPrinter(workingPrinter); 1238 dumpLogs("doAddLocal()"); 1239 if (failed) 1240 throw new pmAddPrinterFailedException(errorLog); 1241 } 1242 1243 } 1244 1245 doAddNetwork()1246 public void doAddNetwork() throws pmGuiException { 1247 try { 1248 getPrinterServer(); 1249 getDescription(); 1250 getNetworkInfo(); 1251 if ((pmMisc.isppdCachefile()) && (usePPD)) { 1252 getMakeModelPPD(); 1253 } else { 1254 getTypeContents(); 1255 } 1256 getFault(); 1257 getBanner(); 1258 getUserAccess(); 1259 updatePrinter(); 1260 } catch (pmIncompleteFormException ie) { 1261 throw new pmIncompleteFormException(ie.getMessage()); 1262 } 1263 1264 boolean exist = false; 1265 1266 try { 1267 exist = PrinterUtil.exists(printer, myTop.ns); 1268 } catch (Exception e) { 1269 Debug.message( 1270 "CLNT:pmInstPr:doAddNetwork:printer exists " + e); 1271 throw new pmGuiException(); 1272 } 1273 1274 if (exist) { 1275 Debug.message( 1276 "CLNT:pmInstPr:Trying to add existing printer: " + printer); 1277 throw new pmPrinterExistsException(); 1278 } 1279 1280 boolean failed = false; 1281 try { 1282 workingPrinter.addLocalPrinter(); 1283 } catch (Exception e) { 1284 failed = true; 1285 } finally { 1286 gatherLogs(workingPrinter); 1287 pmCalls.debugShowPrinter(workingPrinter); 1288 dumpLogs("doAddNetwork()"); 1289 if (failed) 1290 throw new pmAddPrinterFailedException(errorLog); 1291 } 1292 } 1293 1294 doModifyLocalAttached()1295 public void doModifyLocalAttached() throws pmGuiException { 1296 getDescription(); 1297 getFault(); 1298 getBanner(); 1299 1300 if (workingPrinter.getPPD() != null) { 1301 getMakeModelPPD(); 1302 } else { 1303 getTypeContents(); 1304 } 1305 getUserAccess(); 1306 updatePrinter(); 1307 1308 boolean failed = false; 1309 try { 1310 workingPrinter.modifyPrinter(); 1311 } catch (Exception e) { 1312 Debug.warning("CLNT:doModifyLocalAttached: " + e); 1313 failed = true; 1314 } finally { 1315 gatherLogs(workingPrinter); 1316 pmCalls.debugShowPrinter(workingPrinter); 1317 dumpLogs("doModifyLocalAttached()"); 1318 if (failed) 1319 throw new pmModifyPrinterFailedException(errorLog); 1320 } 1321 1322 } 1323 doModifyLocalNetwork()1324 public void doModifyLocalNetwork() throws pmGuiException { 1325 getDescription(); 1326 getNetworkInfo(); 1327 getFault(); 1328 getBanner(); 1329 if (workingPrinter.getPPD() != null) { 1330 getMakeModelPPD(); 1331 } else { 1332 getTypeContents(); 1333 } 1334 getUserAccess(); 1335 updatePrinter(); 1336 1337 boolean failed = false; 1338 try { 1339 workingPrinter.modifyPrinter(); 1340 } catch (Exception e) { 1341 Debug.warning("CLNT:pmInstPr:doModifyLocalNetwork: " + e); 1342 failed = true; 1343 } finally { 1344 gatherLogs(workingPrinter); 1345 pmCalls.debugShowPrinter(workingPrinter); 1346 dumpLogs("doModifyLocalNetwork()"); 1347 if (failed) 1348 throw new pmModifyPrinterFailedException(errorLog); 1349 } 1350 1351 } 1352 1353 doModifyRemote()1354 public void doModifyRemote() throws pmGuiException { 1355 getDescription(); 1356 updatePrinter(); 1357 1358 boolean failed = false; 1359 try { 1360 workingPrinter.modifyPrinter(); 1361 } catch (Exception e) { 1362 Debug.warning("CLNT:doModifyRemote: " + e); 1363 failed = true; 1364 } finally { 1365 gatherLogs(workingPrinter); 1366 pmCalls.debugShowPrinter(workingPrinter); 1367 dumpLogs("doModifyRemote()"); 1368 if (failed) 1369 throw new pmModifyPrinterFailedException(errorLog); 1370 } 1371 1372 } 1373 1374 doClearFields()1375 public void doClearFields() { 1376 1377 if (pnameText != null) 1378 pnameText.setText(""); 1379 if (snameText != null) 1380 snameText.setText(""); 1381 if (descText != null) 1382 descText.setText(""); 1383 if (portCombo != null) 1384 portCombo.setSelectedIndex(0); 1385 if (makeCombo != null) 1386 makeCombo.setSelectedIndex(0); 1387 if (modelCombo != null) 1388 modelCombo.setSelectedIndex(0); 1389 if (ppdCombo != null) 1390 ppdCombo.setSelectedIndex(0); 1391 if (typeCombo != null) 1392 typeCombo.setSelectedIndex(0); 1393 if (faultCombo != null) 1394 faultCombo.setSelectedIndex(0); 1395 if (protocolCombo != null) 1396 protocolCombo.setSelectedIndex(0); 1397 if (destText != null) 1398 destText.setText(""); 1399 1400 if (defaultp.isSelected()) 1401 defaultp.doClick(); 1402 1403 if (bannerCombo != null) 1404 bannerCombo.setSelectedIndex(0); 1405 1406 accessModel.removeListEntries(); 1407 accessModel.addaccessList("all"); 1408 } 1409 doResetFields()1410 public void doResetFields() { 1411 1412 if (workingPrinter != null) { 1413 try { 1414 if (workingPrinter.getComment() != null) 1415 descText.setText(workingPrinter.getComment()); 1416 else 1417 descText.setText(""); 1418 } catch (Exception e) { 1419 Debug.message( 1420 "CLNT:pmInstallPr:doResetFields(): getComment() " + 1421 "Exception: " + e); 1422 } 1423 1424 if (action == Constants.ADDLOCAL || 1425 action == Constants.ADDNETWORK || 1426 action == Constants.MODIFYATTACHED) { 1427 try { 1428 portCombo.setSelectedItem(workingPrinter.getDevice()); 1429 } catch (Exception e) { 1430 Debug.message( 1431 "CLNT:pmInsPr:doResetFields(): getDevice() " + 1432 "Exception: " + e); 1433 } 1434 } 1435 1436 if (action != Constants.MODIFYREMOTE) { 1437 if (workingPrinter.getPPD() != null) { 1438 setMake(); 1439 setModel(); 1440 setPPD(); 1441 } else { 1442 setPrinterType(); 1443 setType(); 1444 } 1445 1446 setFault(); 1447 1448 if (action == Constants.MODIFYNETWORK) 1449 setNetworkInfo(); 1450 1451 try { 1452 accessModel.removeListEntries(); 1453 accessModel.addaccessList( 1454 workingPrinter.getUserAllowList()); 1455 accessList.setListData(accessModel.getAccessList()); 1456 accessList.ensureIndexIsVisible(0); 1457 } catch (Exception e) { 1458 Debug.warning( 1459 "CLNT:InstPr:doResetFields(): addaccessList() " + 1460 "Exception: " + e); 1461 } finally { 1462 accessList.clearSelection(); 1463 } 1464 1465 1466 1467 // selected and banner object out of sync 1468 setBanner(); 1469 } 1470 1471 // selected and printer object out of sync 1472 if ((defaultp.isSelected() && 1473 !workingPrinter.getIsDefaultPrinter()) || 1474 1475 (!defaultp.isSelected() && 1476 workingPrinter.getIsDefaultPrinter())) 1477 1478 defaultp.doClick(); 1479 1480 } 1481 } 1482 1483 1484 isactionModify()1485 public boolean isactionModify() { 1486 1487 if (action == Constants.MODIFYATTACHED || 1488 action == Constants.MODIFYNETWORK || 1489 action == Constants.MODIFYREMOTE) 1490 1491 return true; 1492 else 1493 return false; 1494 } 1495 doReset()1496 public void doReset() { 1497 Debug.message("CLNT:pmInsPr:doReset()"); 1498 if (action == Constants.ADDLOCAL || 1499 action == Constants.ADDNETWORK) { 1500 1501 doClearFields(); 1502 } else { 1503 doResetFields(); 1504 } 1505 1506 // as a side effect, the OK button will regain default status 1507 if (defaultComponent != null) 1508 defaultComponent.requestFocus(); 1509 } 1510 doAction()1511 public void doAction() throws pmGuiException { 1512 1513 // if nameservice, check for login 1514 1515 if (myTop.ns.getNameService().equals("nis") == true || 1516 myTop.ns.getNameService().equals("ldap") == true) { 1517 try { 1518 if (!myTop.ns.isAuth()) { 1519 pmUtility.doLogin(myTop, frame); 1520 } 1521 } catch (pmUserCancelledException e) { 1522 throw new pmLoginFailedException( 1523 pmUtility.getResource("User.cancelled.login.")); 1524 } catch (pmGuiException ge) { 1525 Debug.message("CLNT:pmInstPr: Required login failed."); 1526 pmMessageDialog m = new pmMessageDialog( 1527 frame, 1528 pmUtility.getResource("Error"), 1529 pmUtility.getResource("Required.login.failed."), 1530 myTop, 1531 "LoginFailed"); 1532 m.setVisible(true); 1533 Debug.message("CLNT:pmInstPr:required login failed."); 1534 throw new pmLoginFailedException( 1535 pmUtility.getResource("Required.login.failed.")); 1536 } catch (Exception e) { 1537 Debug.message("CLNT:pmInstPr:login exception: " + e); 1538 pmMessageDialog m = new pmMessageDialog( 1539 frame, 1540 pmUtility.getResource("Error"), 1541 pmUtility.getResource("Required.login.failed."), 1542 myTop, 1543 "LoginFailed"); 1544 m.setVisible(true); 1545 throw new pmLoginFailedException( 1546 pmUtility.getResource("Required.login.failed.")); 1547 } 1548 } 1549 1550 frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 1551 1552 Debug.message("CLNT:pmInstPr:doAction: action " + action); 1553 1554 // Check for confirmation option 1555 if (((myTop.getConfirmOption() == true) && (confirmAction() == true)) 1556 || (myTop.getConfirmOption() == false)) { 1557 1558 try { 1559 1560 switch (action) { 1561 1562 case Constants.ADDLOCAL: 1563 doAddLocal(); 1564 break; 1565 case Constants.ADDNETWORK: 1566 doAddNetwork(); 1567 break; 1568 case Constants.MODIFYATTACHED: 1569 workingPrinter.getPrinterDetails(); 1570 Debug.message( 1571 "CLNT:pmInstPr:Printer Details: server is " + 1572 workingPrinter.getPrintServer()); 1573 doModifyLocalAttached(); 1574 break; 1575 case Constants.MODIFYNETWORK: 1576 // add dest and protocol 1577 workingPrinter.getPrinterDetails(); 1578 Debug.message("CLNT:pmInstPr:Printer Details: server is " + 1579 workingPrinter.getPrintServer()); 1580 doModifyLocalNetwork(); 1581 break; 1582 case Constants.MODIFYREMOTE: 1583 workingPrinter.getPrinterDetails(); 1584 doModifyRemote(); 1585 break; 1586 } 1587 1588 } catch (pmIncompleteFormException fe) { 1589 pmMessageDialog m = new pmMessageDialog( 1590 frame, 1591 pmUtility.getResource("Error"), 1592 fe.getMessage()); // "FormError" 1593 m.setVisible(true); 1594 throw new pmIncompleteFormException(); 1595 } catch (pmPrinterExistsException ee) { 1596 pmMessageDialog m = new pmMessageDialog( 1597 frame, 1598 pmUtility.getResource("Error"), 1599 pmUtility.getResource( 1600 "The.specified.printer.already.exists.")); 1601 m.setVisible(true); 1602 } catch (pmNullSelectedPrinterException ne) { 1603 pmMessageDialog m = new pmMessageDialog( 1604 frame, 1605 pmUtility.getResource("Error"), 1606 pmUtility.getResource( 1607 "The.selected.printer.does.not.exist.")); 1608 m.setVisible(true); 1609 cleanup(); 1610 // frame.dispose(); 1611 } catch (pmAddPrinterFailedException ae) { 1612 pmMessageDialog m = new pmMessageDialog( 1613 frame, 1614 pmUtility.getResource("Error"), 1615 ae.getMessage(), 1616 myTop, 1617 "AddPrinterFailed"); 1618 m.setVisible(true); 1619 1620 } catch (pmModifyPrinterFailedException me) { 1621 pmMessageDialog m = new pmMessageDialog( 1622 frame, 1623 pmUtility.getResource("Error"), 1624 me.getMessage(), 1625 myTop, 1626 "ModifyFailed"); 1627 m.setVisible(true); 1628 } catch (pmGuiException ge) { 1629 pmMessageDialog m = new pmMessageDialog( 1630 frame, 1631 pmUtility.getResource("Application.Error"), 1632 ge.toString()); 1633 m.setVisible(true); 1634 1635 } catch (pmCmdFailedException cfe) { 1636 String msg = cfe.getMessage(); 1637 if (msg == null || msg.length() == 0) 1638 msg = pmUtility.getResource( 1639 "error.message.command-failed"); 1640 1641 pmMessageDialog m = new pmMessageDialog( 1642 frame, 1643 pmUtility.getResource("Command.Failed.Error"), 1644 msg); 1645 m.setVisible(true); 1646 1647 } catch (Exception e) { 1648 pmMessageDialog m = new pmMessageDialog( 1649 frame, 1650 pmUtility.getResource("Unknown.Application.Error"), 1651 e.toString()); 1652 m.setVisible(true); 1653 1654 } finally { 1655 frame.setCursor(Cursor.getDefaultCursor()); 1656 myTop.setLogData(cmdLog, errorLog, warnLog); 1657 myTop.showLogData(actionName); 1658 } 1659 1660 // Update the list of printers 1661 myTop.pmsetPrinterList(); 1662 } 1663 1664 } 1665 confirmAction()1666 public boolean confirmAction() { 1667 if (myTop.getConfirmOption() == true) { 1668 pmOKCancelDialog d = new pmOKCancelDialog(frame, 1669 pmUtility.getResource("Action.Confirmation"), 1670 pmUtility.getResource( 1671 "Continue.action.for.this.printer?")); 1672 d.setVisible(true); 1673 if (d.getValue() != JOptionPane.OK_OPTION) { 1674 pmMessageDialog m = 1675 new pmMessageDialog( 1676 frame, 1677 pmUtility.getResource("Warning"), 1678 pmUtility.getResource("Operation.Cancelled")); 1679 m.setVisible(true); 1680 return false; 1681 } 1682 } 1683 return true; 1684 } 1685 1686 actionportCombo()1687 public void actionportCombo() { 1688 Debug.message("CLNT:pmInstPr:actionportCombo()"); 1689 port = (String)portCombo.getSelectedItem(); 1690 if (port.equals(pmUtility.getResource("Other..."))) { 1691 pmOther o = new pmOther( 1692 frame, 1693 pmUtility.getResource("SPM:Specify.Printer.Port"), 1694 pmUtility.getResource("Enter.printer.port.or.file"), 1695 myTop, 1696 "PrinterPort"); 1697 1698 o.setVisible(true); 1699 if (o.getValue() == JOptionPane.OK_OPTION) { 1700 port = o.deviceName.getText(); 1701 int idx = portCombo.getItemCount(); 1702 try { 1703 if (!port.equals("") && Valid.device(port)) { 1704 portCombo.insertItemAt( 1705 port, (idx > 0) ? idx -1 : idx); 1706 portCombo.setSelectedItem(port); 1707 } else if (!port.equals("")) { 1708 pmMessageDialog m = new pmMessageDialog( 1709 frame, 1710 pmUtility.getResource("Error"), 1711 pmUtility.getResource( 1712 "Device.missing.or.not.writeable."), 1713 myTop, 1714 "PrinterPort"); // "InvalidDevice" 1715 m.setVisible(true); 1716 if (olddevice == null) 1717 portCombo.setSelectedIndex(0); 1718 else 1719 portCombo.setSelectedItem(olddevice); 1720 } else { 1721 if (olddevice == null) 1722 portCombo.setSelectedIndex(0); 1723 else 1724 portCombo.setSelectedItem(olddevice); 1725 } 1726 } catch (Exception de) { 1727 Debug.warning( 1728 "CLNT:pmInstPr:error validating device" + de); 1729 } 1730 1731 } else { // Cancelled out of Other window 1732 if (olddevice == null) 1733 portCombo.setSelectedIndex(0); 1734 else 1735 portCombo.setSelectedItem(olddevice); 1736 } 1737 } 1738 olddevice = (String)portCombo.getSelectedItem(); 1739 if (!port.equals(pmUtility.getResource("Not.Selected"))) { 1740 portCombo.removeItem(pmUtility.getResource("Not.Selected")); 1741 if ((pmMisc.isppdCachefile()) && (usePPD)) { 1742 String makemodel[] = null; 1743 String tmake; 1744 int idx; 1745 String models[] = null; 1746 int i; 1747 1748 makemodel = PrinterUtil.getProbePrinter(olddevice); 1749 if (makemodel != null) { 1750 if ((makemodel[0] != null) && 1751 (!makemodel[0].equals(null))) { 1752 1753 idx = (makemodel[0]).indexOf(" "); 1754 1755 Debug.message( 1756 "CLNT: makemodel[0] = " + makemodel[0]); 1757 Debug.message( 1758 "CLNT: makemodel[1] = " + makemodel[1]); 1759 1760 if (idx != -1) 1761 tmake = new String(makemodel[0].substring(0, idx)); 1762 else 1763 tmake = new String(makemodel[0]); 1764 1765 // Some Manufacturers have multiple names 1766 // Collapse them 1767 if ((tmake.equals("hp")) || 1768 (tmake.equals("Hewlett-Packard")) || 1769 (tmake.equals("HEWLETT-PACKARD"))) 1770 tmake = new String("HP"); 1771 1772 if ((tmake.equals("MINOLTA-QMS")) || 1773 (tmake.equals("MINOLTA"))) 1774 tmake = new String("Minolta"); 1775 1776 if ((tmake.equals("OKI")) || 1777 (tmake.equals("OKI DATA CORP"))) 1778 tmake = new String("Okidata"); 1779 1780 if (tmake.equals("XEROX")) 1781 tmake = new String("Xerox"); 1782 1783 if (tmake.equals("EPSON")) 1784 tmake = new String("Epson"); 1785 1786 Debug.message("CLNT:pmInstPr:Probe:make: " + tmake); 1787 1788 if ((makemodel[1] != null) && 1789 (!makemodel[1].equals(null))) { 1790 1791 Debug.message( 1792 "CLNT:pmInstPr:Probe:model: " + makemodel[1]); 1793 1794 try { 1795 models = PrinterUtil.getModelsList( 1796 tmake.trim()); 1797 } catch (Exception e) { 1798 Debug.warning( 1799 "CLNT:pmInstPr:getModelsList: exception" + e); 1800 } 1801 1802 boolean havemodel = false; 1803 boolean addmake = false; 1804 1805 if (models == null) { 1806 Debug.warning( 1807 "CLNT:pmInstPr:Probe:no models for " 1808 + tmake); 1809 } else { 1810 for (i = 0; i < models.length; i++) { 1811 if (models[i].equalsIgnoreCase( 1812 makemodel[1].trim())) { 1813 havemodel = true; 1814 } 1815 } 1816 // Some Printers do not preceed the model 1817 // name with the Make. If fail, try adding 1818 // Make to front of model 1819 if (!havemodel) { 1820 for (i = 0; i < models.length; i++) { 1821 if (models[i].equalsIgnoreCase( 1822 tmake.trim() + 1823 " " + makemodel[1].trim())) { 1824 havemodel = true; 1825 addmake = true; 1826 1827 } 1828 } 1829 } 1830 1831 if (havemodel) { 1832 makeCombo.setSelectedItem(tmake); 1833 if (!addmake) { 1834 modelCombo.setSelectedItem(makemodel[1]); 1835 Debug.message("CLNT:pmInstPr:model is " + 1836 makemodel[1]); 1837 } else { 1838 modelCombo.setSelectedItem(tmake.trim() + 1839 " " + makemodel[1]); 1840 Debug.message("CLNT:pmInstPr:model is " + 1841 tmake.trim() + " " + makemodel[1]); 1842 } 1843 1844 } 1845 } 1846 } 1847 } 1848 } 1849 } 1850 } 1851 } 1852 actiontypeCombo()1853 public void actiontypeCombo() { 1854 1855 Debug.message("CLNT:pmInstPr:actiontypeCombo()"); 1856 ptype = (String)typeCombo.getSelectedItem(); 1857 1858 if (ptype.equals(pmUtility.getResource("Other..."))) { 1859 pmOther o = new pmOther( 1860 frame, 1861 pmUtility.getResource("SPM:Specify.Printer.Type"), 1862 pmUtility.getResource("Enter.printer.type:"), 1863 myTop, 1864 "PrinterType"); 1865 o.setVisible(true); 1866 if (o.getValue() == JOptionPane.OK_OPTION) { 1867 ptype = o.deviceName.getText(); 1868 int idx = typeCombo.getItemCount(); 1869 try { 1870 if (!ptype.equals("") && Valid.printerType(ptype)) { 1871 typeCombo.insertItemAt( 1872 ptype, (idx > 0) ? idx -1 : idx); 1873 typeCombo.setSelectedItem(ptype); 1874 } else if (!ptype.equals("")) { 1875 pmMessageDialog m = new pmMessageDialog( 1876 frame, 1877 pmUtility.getResource("Error"), 1878 pmUtility.getResource( 1879 "Invalid.printer.type."), 1880 myTop, 1881 "PrinterType"); 1882 m.setVisible(true); 1883 if (oldptype == null) 1884 typeCombo.setSelectedIndex(0); 1885 else 1886 typeCombo.setSelectedItem(oldptype); 1887 } else { 1888 if (oldptype == null) 1889 typeCombo.setSelectedIndex(0); 1890 else 1891 typeCombo.setSelectedItem(oldptype); 1892 } 1893 1894 } catch (Exception pte) { 1895 Debug.message( 1896 "CLNT:pmInstPr:error validating printertype" 1897 + pte); 1898 } 1899 1900 } else { // Cancelled out of Other window 1901 if (oldptype == null) 1902 typeCombo.setSelectedIndex(0); 1903 else 1904 typeCombo.setSelectedItem(oldptype); 1905 } 1906 } 1907 oldptype = (String)typeCombo.getSelectedItem(); 1908 } 1909 1910 // Printer make has been selected actionmakeCombo()1911 public void actionmakeCombo() { 1912 int i; 1913 1914 make = (String)makeCombo.getSelectedItem(); 1915 if (!make.equals(pmUtility.getResource("Not.Selected"))) 1916 makeCombo.removeItem(pmUtility.getResource("Not.Selected")); 1917 1918 1919 if (!oldmake.equals(make)) 1920 modelCombo.removeAllItems(); 1921 1922 oldmake = make; 1923 } 1924 1925 1926 // Get Model actionmodelCombo()1927 public void actionmodelCombo() { 1928 int i; 1929 String models[] = null; 1930 1931 if (!oldmake.equals(make)) { 1932 try { 1933 models = PrinterUtil.getModelsList(make); 1934 } catch (Exception e) { 1935 Debug.warning( 1936 "CLNT:pmInstPr:actionmodelCombo: exception" + e); 1937 } 1938 1939 if (models == null) { 1940 Debug.warning( 1941 "CLNT:pmInstPr:actionmodelCombo:no models for " 1942 + make); 1943 modelCombo.removeAllItems(); 1944 modelCombo.addItem(pmUtility.getResource( 1945 "No.Models.Found")); 1946 } else { 1947 for (i = 0; i < models.length; i++) 1948 modelCombo.addItem(models[i]); 1949 } 1950 } 1951 1952 model = (String)modelCombo.getSelectedItem(); 1953 if (!oldmodel.equals(model)) 1954 ppdCombo.removeAllItems(); 1955 1956 oldmodel = model; 1957 } 1958 1959 actionppdCombo()1960 public void actionppdCombo() { 1961 int i; 1962 int rec = -1; 1963 int idx = -1; 1964 String ppds[] = null; 1965 1966 if (!oldmodel.equals(model)) { 1967 1968 try { 1969 ppds = PrinterUtil.getPPDList(make, model); 1970 1971 } catch (Exception e) { 1972 Debug.warning( 1973 "CLNT:pmInstPr:actionmodelCombo: exception" +e); 1974 } 1975 1976 // Get the ppd files list 1977 // If a recommended ppd is in the list, display it first 1978 if (ppds == null) { 1979 Debug.warning( 1980 "CLNT:pmInstPr:actionmodelCombo: no ppds for " + 1981 make + "/" + model); 1982 ppdCombo.addItem( 1983 pmUtility.getResource("No.PPD.Files.Found")); 1984 } else { 1985 for (i = 0; i < ppds.length; i++) { 1986 ppdCombo.addItem(ppds[i]); 1987 rec = ppds[i].indexOf("recommended"); 1988 if (rec != -1) 1989 idx = i; 1990 } 1991 1992 if (idx != -1) 1993 ppdCombo.setSelectedIndex(idx); 1994 } 1995 } 1996 1997 ppd = (String)ppdCombo.getSelectedItem(); 1998 1999 if (!ppd.equals("")) 2000 ppdCombo.removeItem(""); 2001 2002 } 2003 2004 actionaddButton()2005 public void actionaddButton() { 2006 2007 String tmp = null; 2008 String trimtmp; 2009 Debug.message("CLNT:pmInstPr:actionaddButton()"); 2010 try { 2011 tmp = userText.getText(); 2012 } catch (Exception e) { 2013 Debug.message( 2014 "CLNT:pmInstPr:actionaddButton:UserAccessList empty"); 2015 } 2016 2017 if (tmp == null || tmp.equals("") || tmp.trim().equals("")) { 2018 Debug.message("CLNT:pmInstPr:no username to add"); 2019 } else { 2020 trimtmp = tmp.trim(); 2021 if (accessModel.isduplicate(trimtmp)) 2022 Debug.message("CLNT:pmInstPr:duplicate user"); 2023 2024 else if (!Valid.user(trimtmp)) { 2025 pmMessageDialog m = new pmMessageDialog( 2026 frame, 2027 pmUtility.getResource("Error"), 2028 pmUtility.getResource("Invalid.username")); 2029 // "FormError" 2030 m.setVisible(true); 2031 2032 } else { 2033 if (accessModel.getRowCount() > 0 && 2034 (accessModel.getElementAt(0).equals("all") || 2035 accessModel.getElementAt(0).equals("none"))) 2036 accessModel.removeRow(0); 2037 2038 if (trimtmp.equals("all") || 2039 trimtmp.equals("none")) { 2040 accessModel.removeListEntries(); 2041 } 2042 2043 accessModel.addaccessList(trimtmp); 2044 accessList.setListData(accessModel.getAccessList()); 2045 int rw = accessModel.getRowCount(); 2046 accessList.setSelectedIndex(rw - 1); 2047 accessList.ensureIndexIsVisible(rw -1); 2048 } 2049 2050 } 2051 userText.setText(""); 2052 userText.requestFocus(); 2053 2054 ascrollPane.revalidate(); 2055 ascrollPane.repaint(); 2056 2057 frame.repaint(); 2058 } 2059 actiondeleteButton()2060 public void actiondeleteButton() { 2061 Debug.message("CLNT:pmInstPr:actiondeleteButton()"); 2062 int row; 2063 int rcount; 2064 int idx; 2065 2066 row = accessList.getSelectedIndex(); 2067 rcount = accessModel.getRowCount(); 2068 2069 if ((row >= 0 && rcount > 0) && (!accessList.isSelectionEmpty())) { 2070 accessModel.removeRow(row); 2071 rcount = accessModel.getRowCount(); 2072 if (rcount != 0) { 2073 if (row == rcount) 2074 accessList.setSelectedIndex(row - 1); 2075 idx = accessList.getFirstVisibleIndex(); 2076 if (idx > 0 && idx < rcount) 2077 accessList.ensureIndexIsVisible(idx - 1); 2078 } 2079 } 2080 userText.requestFocus(); 2081 frame.repaint(); 2082 } 2083 2084 2085 // For ok/cancel cleanup()2086 public void cleanup() { 2087 2088 if (action == Constants.ADDLOCAL) { 2089 myTop.localinstallView = null; 2090 } 2091 2092 if (action == Constants.ADDNETWORK) { 2093 myTop.networkinstallView = null; 2094 } 2095 2096 } 2097 pmScreendispose()2098 public void pmScreendispose() { 2099 frame.dispose(); 2100 } 2101 actionokButton()2102 public void actionokButton() { 2103 2104 Debug.message("CLNT:pmInstPr:actionokButton()"); 2105 boolean incomplete = false; 2106 2107 try { 2108 doAction(); 2109 } catch (pmLoginFailedException le) { 2110 // User already notified 2111 Debug.message("CLNT:pmInstPr:pmLoginFailedException caught"); 2112 } catch (pmIncompleteFormException fe) { 2113 // User already notified 2114 incomplete = true; 2115 } catch (pmGuiException ge) { 2116 Debug.message("CLNT:pmInstPr:login Exception, task cancelled"); 2117 } 2118 2119 if (!incomplete) { 2120 cleanup(); 2121 myTop.pmsetdefaultpLabel(); 2122 Debug.message("CLNT:pmInstPr:actionokbutton(): work done"); 2123 pmCalls.debugShowPrinter(workingPrinter); 2124 frame.setVisible(false); 2125 frame.repaint(); 2126 // frame.dispose(); 2127 myTop.scrollPane.revalidate(); 2128 myTop.scrollPane.repaint(); 2129 } 2130 } 2131 actionapplyButton()2132 public void actionapplyButton() { 2133 2134 Debug.message("CLNT:pmInstPr:actionapplyButton()"); 2135 2136 try { 2137 doAction(); 2138 } catch (pmLoginFailedException le) { 2139 // User already notified 2140 Debug.message("CLNT:pmInstPr:pmLoginFailedException caught"); 2141 } catch (pmGuiException ge) { 2142 Debug.message("CLNT:pmInstPr:login Exception, task cancelled"); 2143 } 2144 2145 myTop.pmsetdefaultpLabel(); 2146 Debug.message("CLNT:pmInstPr:actionapplybutton(): work done"); 2147 pmCalls.debugShowPrinter(workingPrinter); 2148 myTop.scrollPane.revalidate(); 2149 myTop.scrollPane.repaint(); 2150 } 2151 2152 actionresetButton()2153 public void actionresetButton() { 2154 Debug.message("CLNT:pmInstPr:actionresetButton()"); 2155 doReset(); 2156 frame.repaint(); 2157 } 2158 actioncancelButton()2159 public void actioncancelButton() { 2160 Debug.message("CLNT:pmInstPr:actioncancelButton()"); 2161 cleanup(); 2162 frame.setVisible(false); 2163 frame.repaint(); 2164 // frame.dispose(); 2165 } 2166 actionhelpButton()2167 public void actionhelpButton() { 2168 Debug.message("CLNT:pmInstPr:actionhelpButton()"); 2169 myTop.showHelpItem(helpTag); 2170 } 2171 Show()2172 public void Show() { 2173 2174 Debug.message("CLNT:pmInstPr:Show()"); 2175 frame.getContentPane().add("North", this); 2176 frame.pack(); 2177 frame.setVisible(true); 2178 frame.repaint(); 2179 2180 // set focus to initial field, depending on which action is tbd 2181 // this seems to work best after pack() 2182 2183 // default button is always OK, for now... 2184 // frame.getRootPane().setDefaultButton (okButton); 2185 okButton.setAsDefaultButton(); 2186 2187 2188 Debug.info("Show: default comp is " + defaultComponent); 2189 if (defaultComponent != null) { 2190 defaultComponent.requestFocus(); 2191 } 2192 2193 } 2194 } 2195