List of usage examples for javax.swing.tree DefaultTreeModel DefaultTreeModel
@ConstructorProperties({ "root" }) public DefaultTreeModel(TreeNode root)
From source file:view.CertificatePropertiesDialog.java
private void setupTree(Certificate[] certificateChain) { DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) jTree1.getCellRenderer(); Icon closedIcon = new ImageIcon(MainWindow.class.getResource("/image/certificate.png")); renderer.setLeafIcon(closedIcon);//from w w w. j av a2 s. com renderer.setOpenIcon(closedIcon); renderer.setClosedIcon(closedIcon); BasicTreeUI treeUI = (BasicTreeUI) jTree1.getUI(); treeUI.setCollapsedIcon(null); treeUI.setExpandedIcon(null); if (null != certificateChain) { if (certificateChain.length > 0) { DefaultMutableTreeNode dmtn[] = new DefaultMutableTreeNode[certificateChain.length]; boolean needCheck = true; for (int i = (certificateChain.length - 1); i >= 0; i--) { if (!needCheck) { dmtn[i] = new DefaultMutableTreeNode(getCertificateCN(certificateChain[i])); if (i < (certificateChain.length - 1)) { dmtn[i + 1].add(dmtn[i]); } certChainList.add((X509Certificate) certificateChain[i]); continue; } if (CCInstance.getInstance().isTrustedCertificate((X509Certificate) certificateChain[i])) { dmtn[i] = new DefaultMutableTreeNode(getCertificateCN(certificateChain[i])); needCheck = false; } else if (CCInstance.getInstance() .hasTrustedIssuerCertificate((X509Certificate) certificateChain[i]) != null) { dmtn[i] = new DefaultMutableTreeNode(getCertificateCN(certificateChain[i])); } else { dmtn[i] = new DefaultMutableTreeNode("(!)" + getCertificateCN(certificateChain[i])); } if (i < (certificateChain.length - 1)) { dmtn[i + 1].add(dmtn[i]); } certChainList.add((X509Certificate) certificateChain[i]); } TreeModel tm = new DefaultTreeModel(dmtn[certificateChain.length - 1]); jTree1.setModel(tm); expandTree(jTree1); } } if (null != jTree1.getTreeExpansionListeners()) { if (null != jTree1.getTreeExpansionListeners()[0]) { jTree1.removeTreeExpansionListener(jTree1.getTreeExpansionListeners()[0]); } } }
From source file:view.MainWindow.java
/** * Creates new form MainWindow/*from w w w . ja v a 2 s. com*/ */ public MainWindow() { initComponents(); updateText(); List<Image> icons = new ArrayList<>(); icons.add(new ImageIcon(getClass().getResource("/image/aCCinaPDF_logo_icon32.png")).getImage()); this.setIconImages(icons); setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); workspacePanel.setParent((MainWindow) this); populateDriveComboBox(); dmtn = new DefaultMutableTreeNode("0 " + Bundle.getBundle().getString("tn.documentsLoaded")); TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); setupTreePopups(); setupDropListener(); DefaultTreeCellRenderer renderer1 = (DefaultTreeCellRenderer) jtOpenedDocuments.getCellRenderer(); Icon closedIcon = new ImageIcon(MainWindow.class.getResource("/image/pdf_ico.jpg")); renderer1.setLeafIcon(closedIcon); DefaultTreeCellRenderer renderer2 = (DefaultTreeCellRenderer) jtExplorer.getCellRenderer(); renderer2.setLeafIcon(closedIcon); tfProcurar.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { refreshTree(tfProcurar.getText()); } @Override public void removeUpdate(DocumentEvent e) { refreshTree(tfProcurar.getText()); } @Override public void changedUpdate(DocumentEvent e) { } }); KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher((MainWindow) this); refreshTree(null); ctrl.setPrintMenuItem(menuItemPrint); }
From source file:view.MainWindow.java
public void closeDocument(boolean showCloseDialog) { if (!workspacePanel.getStatus().equals(WorkspacePanel.Status.READY)) { return;//from www . jav a2 s. c o m } if (!files.isEmpty()) { int opt = -1; if (showCloseDialog) { String msg; if (jtOpenedDocuments.getSelectionRows().length == 1) { msg = Bundle.getBundle().getString("msg.closeSelectedDocument"); } else { msg = Bundle.getBundle().getString("msg.closeSelectedDocuments"); } Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } boolean closedOpenedDocument = false; if (!showCloseDialog || opt == JOptionPane.YES_OPTION) { // Apagar da lista de documentos abertos for (int i = jtOpenedDocuments.getSelectionRows().length - 1; i >= 0; i--) { int index = jtOpenedDocuments.getSelectionRows()[i]; String path = jtOpenedDocuments.getPathForRow(index).getPathComponent(1).toString(); files.remove(new File(path)); if (null != openedFile) { if (openedFile.equals(new File(path))) { closedOpenedDocument = true; clearOpenedDocument(); setTitle(null); } } } dmtn.removeAllChildren(); for (File file : files) { dmtn.insert(new DefaultMutableTreeNode(file), 0); } int numOpened = dmtn.getChildCount(); if (1 == numOpened) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + " :"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(numOpened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); if (closedOpenedDocument && !files.isEmpty()) { File first = files.get(files.size() - 1); jtOpenedDocuments.setSelectionRow(0); ctrl.openDocument(first.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = first; } } } }
From source file:view.MainWindow.java
public void closeDocuments(ArrayList<File> listaD, boolean showCloseDialog) { if (workspacePanel.getStatus().equals(WorkspacePanel.Status.SIGNING)) { if (listaD.contains(openedFile)) { String msg = Bundle.getBundle().getString("msg.cancelSignatureAndClose1") + " " + (listaD.size() == 1 ? Bundle.getBundle().getString("msg.cancelSignatureAndClose2") : Bundle.getBundle().getString("msg.cancelSignatureAndClose3")); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(this, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt != JOptionPane.YES_OPTION) { return; }//from w w w .j a v a2 s .c o m } } if (!listaD.isEmpty()) { int opt = -1; if (showCloseDialog) { String msg; if (listaD.size() == 1) { msg = Bundle.getBundle().getString("msg.closeSelectedDocument"); } else { msg = Bundle.getBundle().getString("msg.closeSelectedDocuments"); } Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } if (!showCloseDialog || opt == JOptionPane.YES_OPTION) { // Apagar da lista de documentos abertos boolean closedOpenedDocument = false; for (int r = jtOpenedDocuments.getRowCount() - 1; r >= 0; r--) { String str = ""; Object[] paths = jtOpenedDocuments.getPathForRow(r).getPath(); for (int i = 1; i < paths.length; i++) { str += paths[i]; if (i + 1 < paths.length) { str += File.separator; } } File currFile = new File(str.replaceAll("\\\\+", "\\\\")); for (File f : listaD) { if (f.getAbsolutePath().replaceAll("\\\\+", "\\\\").equals(currFile.getAbsolutePath())) { dmtn.remove(r); files.remove(currFile); if (null != openedFile) { if (openedFile.equals(currFile)) { closedOpenedDocument = true; clearOpenedDocument(); setTitle(null); } } break; } } } int numOpened = files.size(); if (1 == numOpened) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(numOpened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); if (closedOpenedDocument && !files.isEmpty()) { File first = files.get(files.size() - 1); jtOpenedDocuments.setSelectionRow(0); ctrl.openDocument(first.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = first; } } } }
From source file:view.MainWindow.java
public boolean loadPdf(File selectedFile, boolean showOpenDialog) { if (null == openedFile || !openedFile.equals(selectedFile)) { if (selectedFile.isFile() && selectedFile.exists()) { try { if (null == dmtn) { lblOpenedDocuments.setText("0 " + Bundle.getBundle().getString("tn.documentsLoaded")); dmtn = new DefaultMutableTreeNode(null); }//from www . ja v a 2 s . c om boolean exists = false; for (int i = 0; i < dmtn.getChildCount(); i++) { if (String.valueOf(dmtn.getChildAt(i)).equals(selectedFile.getAbsolutePath())) { exists = true; jtOpenedDocuments.setSelectionRow(i); ctrl.openDocument(selectedFile.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = selectedFile; break; } } if (!exists) { if (testPdf(selectedFile)) { dmtn.insert(new DefaultMutableTreeNode(selectedFile), 0); TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); // jtOpenedDocuments.setSelectionRow(1); int numOpened = dmtn.getChildCount(); if (1 == numOpened) { lblOpenedDocuments .setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments.setText( numOpened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } if (null == openedFile) { jtOpenedDocuments.setSelectionRow(0); jtOpenedDocuments.scrollRowToVisible(0); ctrl.openDocument(selectedFile.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); files.add(new File(selectedFile.getAbsolutePath())); openedFile = selectedFile; return true; } else { jtOpenedDocuments.setSelectionRow(1); jtOpenedDocuments.scrollRowToVisible(1); if (showOpenDialog) { String msg = Bundle.getBundle().getString("msg.openNewOrKeepCurrent"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("opt.justAdd") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { jtOpenedDocuments.setSelectionRow(0); ctrl.openDocument(selectedFile.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = selectedFile; } } files.add(new File(selectedFile.getAbsolutePath())); return true; } } else { errorList.add(selectedFile.getAbsolutePath()); showErrors(); } } } catch (Exception e) { controller.Logger.getLogger().addEntry(e); } } } return false; }
From source file:view.MainWindow.java
private void refreshOpenedDocumentsList() { int tempCount = dmtn.getChildCount(); lblOpenedDocuments.setText("0 " + Bundle.getBundle().getString("tn.documentsLoaded")); dmtn = new DefaultMutableTreeNode(null); int num = 0;/*from www.j av a2 s. c om*/ if (!files.isEmpty()) { File last = null; for (File file : files) { dmtn.insert(new DefaultMutableTreeNode(file), 0); num++; if (files.size() == num) { last = file; } } if (null == openedFile) { ctrl.openDocument(last.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = last; int opened = dmtn.getChildCount(); if (opened == 1) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); jtOpenedDocuments.setSelectionRow(0); jtOpenedDocuments.scrollRowToVisible(0); } else if (tempCount != dmtn.getChildCount()) { String msg = Bundle.getBundle().getString("msg.openNewOrKeepCurrent2"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("opt.justAdd") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { ctrl.openDocument(last.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = last; int opened = dmtn.getChildCount(); if (opened == 1) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); jtOpenedDocuments.setSelectionRow(0); jtOpenedDocuments.scrollRowToVisible(0); } else { int opened = dmtn.getChildCount(); if (opened == 1) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); jtOpenedDocuments.setSelectionRow(num); jtOpenedDocuments.scrollRowToVisible(num); } } } }
From source file:view.MultipleValidationDialog.java
/** * Creates new form MultipleValidationDialog * * @param parent/*from w ww .j a va2 s. c o m*/ * @param modal * @param files */ public MultipleValidationDialog(java.awt.Frame parent, boolean modal, final ArrayList<File> files) { super(parent, modal); initComponents(); updateText(); this.setSize(1024, 768); lblRevision.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); final DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(null); panelSignatureDetails.setVisible(false); btnSaveInFile.setEnabled(false); jtValidation.setModel(null); jtValidation.setVisible(false); progressBar.setString(Bundle.getBundle().getString("pb.validating") + " 1 " + Bundle.getBundle().getString("of") + " " + files.size()); progressBar.setMaximum(files.size()); final ValidationListener vl = new ValidationListener() { int numParsed = 1; @Override public void onValidationComplete(SignatureValidation sv) { Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> tempEntry = null; while (tempEntry == null) { for (Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> entry : hmValidation .entrySet()) { if (entry.getKey().getFilename().equals(sv.getFilename())) { tempEntry = entry; break; } } if (sv.isCertification()) { if (sv.isValid()) { tempEntry.getKey() .setValidationStatus(ValidationFileListEntry.ValidationStatus.CERTIFIED); } else { tempEntry.getKey() .setValidationStatus(ValidationFileListEntry.ValidationStatus.INVALID); } } else if (sv.isValid()) { tempEntry.getKey().setValidationStatus(ValidationFileListEntry.ValidationStatus.ALL_OK); } else { tempEntry.getKey().setValidationStatus(ValidationFileListEntry.ValidationStatus.INVALID); } tempEntry.getValue().add(sv); } } }; Runnable r = new Runnable() { @Override public void run() { int numParsed = 0; for (File file : files) { try { ArrayList<SignatureValidation> svList = new ArrayList<>(); int numSigs = CCInstance.getInstance().getNumberOfSignatures(file.getAbsolutePath()); ValidationFileListEntry vfle = new ValidationFileListEntry(file.getAbsolutePath(), numSigs, ValidationFileListEntry.ValidationStatus.UNKNOWN); hmValidation.put(vfle, svList); CCInstance.getInstance().validatePDF(file.getAbsolutePath(), vl); dmtn.insert(new DefaultMutableTreeNode(vfle), 0); } catch (IOException | DocumentException | GeneralSecurityException ex) { if (ex.getLocalizedMessage().contains("keystore\\aCCinaPDF_cacerts")) { JOptionPane.showMessageDialog(MultipleValidationDialog.this, Bundle.getBundle().getString("errorDefaultKeystore"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(MultipleValidationDialog.this, Bundle.getBundle().getString("unknownErrorLog"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); } break; } numParsed++; progressBar.setValue(numParsed); progressBar.setString(Bundle.getBundle().getString("pb.validating") + " " + numParsed + " " + Bundle.getBundle().getString("of") + " " + files.size()); TreeModel tm = new DefaultTreeModel(dmtn); jtFiles.setModel(tm); } progressBar.setString(Bundle.getBundle().getString("pb.validationComplete")); if (numParsed > 0) { jtFiles.setSelectionRow(0); btnSaveInFile.setEnabled(true); } } }; Thread t = new Thread(r); t.start(); jtValidation.setVisible(true); FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer(); jtFiles.setCellRenderer(renderer1); ToolTipManager.sharedInstance().registerComponent(jtFiles); ValidationTreeCellRenderer renderer = new ValidationTreeCellRenderer(); jtValidation.setCellRenderer(renderer); }
From source file:view.MultipleValidationDialog.java
private void jtFilesValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jtFilesValueChanged jtValidation.setModel(null);//from www . ja v a 2 s . c om ArrayList<SignatureValidation> svList = null; if (jtFiles.getSelectionRows().length > 1) { jtFiles.setSelectionPath(evt.getOldLeadSelectionPath()); return; } if (evt.getNewLeadSelectionPath() == null) { panelSignatureDetails.setVisible(false); return; } for (Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> entry : hmValidation.entrySet()) { int numSigs = CCInstance.getInstance().getNumberOfSignatures(entry.getKey().getFilename()); if (String.valueOf(evt.getPath().getLastPathComponent()) .equals("(" + numSigs + ") " + entry.getKey().getFilename())) { svList = entry.getValue(); break; } } final DefaultMutableTreeNode top = new DefaultMutableTreeNode(null); if (svList == null) { return; } if (svList.isEmpty()) { panelSignatureDetails.setVisible(false); DefaultMutableTreeNode noSignatures = new TreeNodeWithState(Bundle.getBundle().getString("notSigned"), TreeNodeWithState.State.NOT_SIGNED); top.add(noSignatures); TreeModel tm = new DefaultTreeModel(top); jtValidation.setModel(tm); return; } for (SignatureValidation sv : svList) { DefaultMutableTreeNode sig = new DefaultMutableTreeNode(sv); TreeNodeWithState childChanged = null; if (sv.isCertification()) { if (sv.isValid()) { if (sv.isChanged() || !sv.isCoversEntireDocument()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.1") + "<br>" + Bundle.getBundle().getString("tn.2") + "</html>", TreeNodeWithState.State.CERTIFIED_WARNING); } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("certifiedOk"), TreeNodeWithState.State.CERTIFIED); } } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("changedAfterCertified"), TreeNodeWithState.State.INVALID); } } else if (sv.isValid()) { if (sv.isChanged()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.3") + "<br>" + Bundle.getBundle().getString("tn.4") + "</html>", TreeNodeWithState.State.VALID_WARNING); } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("signedOk"), TreeNodeWithState.State.VALID); } } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("signedChangedOrCorrupted"), TreeNodeWithState.State.INVALID); } TreeNodeWithState childVerified = null; if (sv.getOcspCertificateStatus().equals(CertificateStatus.OK) || sv.getCrlCertificateStatus().equals(CertificateStatus.OK)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certOK"), TreeNodeWithState.State.VALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.REVOKED) || sv.getCrlCertificateStatus().equals(CertificateStatus.REVOKED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certRevoked"), TreeNodeWithState.State.INVALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHECKED) && sv.getCrlCertificateStatus().equals(CertificateStatus.UNCHECKED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certNotVerified"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHAINED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certNotChained"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.EXPIRED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certExpired"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.CHAINED_LOCALLY)) { childVerified = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.5") + "<br>" + Bundle.getBundle().getString("tn.6") + "</html>", TreeNodeWithState.State.VALID_WARNING); } TreeNodeWithState childTimestamp = null; if (sv.isValidTimeStamp()) { childTimestamp = new TreeNodeWithState(Bundle.getBundle().getString("validTimestamp"), TreeNodeWithState.State.VALID); } else { childTimestamp = new TreeNodeWithState(Bundle.getBundle().getString("signerDateTime"), TreeNodeWithState.State.WARNING); } sig.add(childChanged); sig.add(childVerified); sig.add(childTimestamp); top.add(sig); } TreeModel tm = new DefaultTreeModel(top); jtValidation.setModel(tm); if (jtValidation.getRowCount() > 0) { jtValidation.setSelectionRow(jtValidation.getRowCount() - 1); } }
From source file:view.WorkspacePanel.java
private void startValidationThread() { status = Status.VALIDATING;//from www . ja va 2s .c om svList.clear(); jtValidation.clearSelection(); jtValidation.setModel(null); showSignatureValidationDetails(null); Runnable r = new Runnable() { @Override public void run() { try { progressBar.setValue(0); jtValidation.setModel(null); jtValidation.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jtValidation.setRootVisible(false); ValidationTreeCellRenderer renderer = new ValidationTreeCellRenderer(); jtValidation.setCellRenderer(renderer); final int numSigs = CCInstance.getInstance() .getNumberOfSignatures(document.getDocumentLocation()); if (numSigs > 0) { jScrollPane2.setVisible(true); progressBar.setString(Bundle.getBundle().getString("pb.validatingSignature") + " 1 " + Bundle.getBundle().getString("of") + " " + numSigs); progressBar.setMaximum(numSigs); final DefaultMutableTreeNode top = new DefaultMutableTreeNode(null); ValidationListener vl = new ValidationListener() { int numParsed = 1; @Override public void onValidationComplete(SignatureValidation sv) { if (status.equals(Status.VALIDATING)) { sv.setListener(WorkspacePanel.this); svList.add(sv); DefaultMutableTreeNode sig = new DefaultMutableTreeNode(sv); TreeNodeWithState childChanged = null; if (sv.isCertification()) { if (sv.isValid()) { if (sv.isChanged() || !sv.isCoversEntireDocument()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.1") + "<br>" + Bundle.getBundle().getString("tn.2") + "</html>", TreeNodeWithState.State.CERTIFIED_WARNING); } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("certifiedOk"), TreeNodeWithState.State.CERTIFIED); } } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("changedAfterCertified"), TreeNodeWithState.State.INVALID); } } else if (sv.isValid()) { if (sv.isChanged()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.3") + "<br>" + Bundle.getBundle().getString("tn.4") + "</html>", TreeNodeWithState.State.VALID_WARNING); } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("signedOk"), TreeNodeWithState.State.VALID); } } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("signedChangedOrCorrupted"), TreeNodeWithState.State.INVALID); } TreeNodeWithState childVerified = null; if (sv.getOcspCertificateStatus().equals(CertificateStatus.OK) || sv.getCrlCertificateStatus().equals(CertificateStatus.OK)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certOK"), TreeNodeWithState.State.VALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.REVOKED) || sv.getCrlCertificateStatus().equals(CertificateStatus.REVOKED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certRevoked"), TreeNodeWithState.State.INVALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHECKED) && sv.getCrlCertificateStatus().equals(CertificateStatus.UNCHECKED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certNotVerified"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHAINED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certNotChained"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.EXPIRED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certExpired"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus() .equals(CertificateStatus.CHAINED_LOCALLY)) { childVerified = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.5") + "<br>" + Bundle.getBundle().getString("tn.6") + "</html>", TreeNodeWithState.State.VALID_WARNING); } TreeNodeWithState childTimestamp = null; if (sv.isValidTimeStamp()) { childTimestamp = new TreeNodeWithState( Bundle.getBundle().getString("validTimestamp"), TreeNodeWithState.State.VALID); } else { childTimestamp = new TreeNodeWithState( Bundle.getBundle().getString("signerDateTime"), TreeNodeWithState.State.WARNING); } sig.add(childChanged); sig.add(childVerified); sig.add(childTimestamp); top.add(sig); TreeModel tm = new DefaultTreeModel(top); jtValidation.setModel(tm); progressBar.setValue(progressBar.getValue() + 1); numParsed++; progressBar.setString( Bundle.getBundle().getString("pb.validatingSignature") + " " + numParsed + " " + Bundle.getBundle().getString("of") + " " + numSigs); } else { CCInstance.getInstance().setValidating(false); } } }; CCInstance.getInstance().validatePDF(document.getDocumentLocation(), vl); status = Status.READY; jtValidation.setVisible(true); progressBar.setString(Bundle.getBundle().getString("pb.validationCompleted")); if (rightPanel.isVisible() && jtValidation.getRowCount() > 0) { jtValidation.setSelectionRow(jtValidation.getRowCount() - 1); } imagePanel.setSignatureValidationList(svList); panelValidationResult.setVisible(true); status = Status.READY; } else { progressBar.setString(Bundle.getBundle().getString("notSigned")); status = Status.READY; jScrollPane2.setVisible(false); } } catch (IOException | DocumentException | GeneralSecurityException ex) { controller.Logger.getLogger().addEntry(ex); status = Status.READY; progressBar.setString(Bundle.getBundle().getString("validationError")); jScrollPane2.setVisible(false); } } }; Thread t = new Thread(r); t.start(); }
From source file:wilos.presentation.web.tree.TreeBean.java
public TreeBean() { this.model = new DefaultTreeModel(this.getDefaultTree()); }