List of usage examples for javax.swing JOptionPane CANCEL_OPTION
int CANCEL_OPTION
To view the source code for javax.swing JOptionPane CANCEL_OPTION.
Click Source Link
From source file:net.sf.jabref.gui.desktop.JabRefDesktop.java
public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, BibDatabaseContext databaseContext, String link, UnknownExternalFileType fileType) throws IOException { String cancelMessage = Localization.lang("Unable to open file."); String[] options = new String[] { Localization.lang("Define '%0'", fileType.getName()), Localization.lang("Change file type"), Localization.lang("Cancel") }; String defOption = options[0]; int answer = JOptionPane.showOptionDialog(frame, Localization.lang(//w ww.ja v a 2s . co m "This external link is of the type '%0', which is undefined. What do you want to do?", fileType.getName()), Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, defOption); if (answer == JOptionPane.CANCEL_OPTION) { frame.output(cancelMessage); return false; } else if (answer == JOptionPane.YES_OPTION) { // User wants to define the new file type. Show the dialog: ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon()); ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(frame, newType); editor.setVisible(true); if (editor.okPressed()) { // Get the old list of types, add this one, and update the list in prefs: List<ExternalFileType> fileTypes = new ArrayList<>( ExternalFileTypes.getInstance().getExternalFileTypeSelection()); fileTypes.add(newType); Collections.sort(fileTypes); ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes); // Finally, open the file: return openExternalFileAnyFormat(databaseContext, link, Optional.of(newType)); } else { // Canceled: frame.output(cancelMessage); return false; } } else { // User wants to change the type of this link. // First get a model of all file links for this entry: FileListTableModel tModel = new FileListTableModel(); Optional<String> oldValue = entry.getFieldOptional(FieldName.FILE); oldValue.ifPresent(tModel::setContent); FileListEntry flEntry = null; // Then find which one we are looking at: for (int i = 0; i < tModel.getRowCount(); i++) { FileListEntry iEntry = tModel.getEntry(i); if (iEntry.link.equals(link)) { flEntry = iEntry; break; } } if (flEntry == null) { // This shouldn't happen, so I'm not sure what to put in here: throw new RuntimeException("Could not find the file list entry " + link + " in " + entry); } FileListEntryEditor editor = new FileListEntryEditor(frame, flEntry, false, true, databaseContext); editor.setVisible(true, false); if (editor.okPressed()) { // Store the changes and add an undo edit: String newValue = tModel.getStringRepresentation(); UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, oldValue.orElse(null), newValue); entry.setField(FieldName.FILE, newValue); frame.getCurrentBasePanel().getUndoManager().addEdit(ce); frame.getCurrentBasePanel().markBaseChanged(); // Finally, open the link: return openExternalFileAnyFormat(databaseContext, flEntry.link, flEntry.type); } else { // Canceled: frame.output(cancelMessage); return false; } } }
From source file:fi.elfcloud.client.dialog.ModifyDataItemDialog.java
@Override public int showDialog() { setVisible(true);// w w w . ja v a 2 s. c om if (answer) { return JOptionPane.OK_OPTION; } return JOptionPane.CANCEL_OPTION; }
From source file:de.ipk_gatersleben.ag_nw.graffiti.plugins.gui.webstart.MainM.java
/** * Constructs a new instance of the editor. * @param addPluginFile/* w w w.j a v a2 s . c o m*/ */ public MainM(String applicationName, String[] args, String[] addon, SplashScreenInterface splashScreen, String addPluginFile, final boolean showMainFrame) { setupLogger(); ClassLoader cl = this.getClass().getClassLoader(); String path = this.getClass().getPackage().getName().replace('.', '/'); ImageIcon icon = new ImageIcon(cl.getResource(path + "/vanted_logo.png")); if (splashScreen != null && (splashScreen instanceof DBEsplashScreen)) { ((DBEsplashScreen) splashScreen).setIconImage(icon.getImage()); } splashScreen.setVisible(showMainFrame); GravistoMainHelper.createApplicationSettingsFolder(splashScreen); if (!showMainFrame && !(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted")).exists() && !(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected")).exists()) { // command line version automatically rejects // kegg try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected").createNewFile(); } catch (Exception e1) { e1.printStackTrace(); } } if (!(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted")).exists() && !(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected")).exists()) { ReleaseInfo.setIsFirstRun(true); splashScreen.setVisible(false); splashScreen.setText("Request KEGG License Status"); int result = askForEnablingKEGG(); if (result == JOptionPane.YES_OPTION) { try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted").createNewFile(); } catch (IOException e) { ErrorMsg.addErrorMessage(e); } } if (result == JOptionPane.NO_OPTION) { try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected").createNewFile(); } catch (IOException e) { ErrorMsg.addErrorMessage(e); } } if (result == JOptionPane.CANCEL_OPTION) { JOptionPane.showMessageDialog(null, "Startup of VANTED is aborted.", "VANTED Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } splashScreen.setVisible(true); } GravistoMainHelper.initApplicationExt(args, splashScreen, cl, addPluginFile, addon); }
From source file:components.DialogDemo.java
/** Creates the panel shown by the first tab. */ private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;/*from w ww . j a v a2 s . c o m*/ final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("OK (in the L&F's words)"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green."); //yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("Ewww!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("Me neither!"); } else { setLabel("Come on -- tell me!"); } //yes/no (not in those words) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No way!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("You're kidding!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("I don't like them, either."); } else { setLabel("Come on -- 'fess up!"); } //yes/no/cancel (not in those words) } else if (command == yncCommand) { Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like some green eggs to go " + "with that ham?", "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Here you go: green eggs and ham!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("OK, just the ham, then."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to eat them!"); } else { setLabel("Please tell me what you want!"); } } return; } }); return createPane(simpleDialogDesc + ":", radioButtons, showItButton); }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
public boolean canExit() { if (hasChanges) { /*//from w ww. j av a2 s . c o m * Wenn es ungespeicherte Aenderungen gibt, dann Benutzer fragen */ int ret = JOptionPane.showConfirmDialog(getMainFrame(), "Save changes before exit?", "", JOptionPane.YES_NO_CANCEL_OPTION); switch (ret) { case JOptionPane.CANCEL_OPTION: return false; case JOptionPane.NO_OPTION: return true; case JOptionPane.YES_OPTION: /* * Speichern anstossen */ saveDatabase(); /* * Nur wenn Speichern erfolgreich war 'true' zurueckgeben */ return !hasChanges; default: return false; } } else { return true; } }
From source file:com.igormaznitsa.zxpspritecorrector.files.TAPPlugin.java
@Override public void writeTo(final File file, final ZXPolyData data, final SessionData session) throws IOException { final int saveAsSeparateFiles = JOptionPane.showConfirmDialog(this.mainFrame, "Save each block as a separated file?", "Separate files", JOptionPane.YES_NO_CANCEL_OPTION); if (saveAsSeparateFiles == JOptionPane.CANCEL_OPTION) return;//from w ww . j a v a2 s . co m final String baseName = file.getName(); final String baseZXName = FilenameUtils.getBaseName(baseName); if (saveAsSeparateFiles == JOptionPane.YES_OPTION) { final FileNameDialog fileNameDialog = new FileNameDialog(this.mainFrame, "Saving as separated files", new String[] { addNumberToFileName(baseName, 0), addNumberToFileName(baseName, 1), addNumberToFileName(baseName, 2), addNumberToFileName(baseName, 3) }, new String[] { prepareNameForTAP(baseZXName, 0), prepareNameForTAP(baseZXName, 1), prepareNameForTAP(baseZXName, 2), prepareNameForTAP(baseZXName, 3) }, null); fileNameDialog.setVisible(true); if (fileNameDialog.approved()) { final String[] fileNames = fileNameDialog.getFileName(); final String[] zxNames = fileNameDialog.getZxName(); for (int i = 0; i < 4; i++) { final byte[] headerblock = makeHeaderBlock(zxNames[i], data.getInfo().getStartAddress(), data.length()); final byte[] datablock = makeDataBlock(data.getDataForCPU(i)); final byte[] dataToSave = JBBPOut.BeginBin().Byte(wellTapBlock(headerblock)) .Byte(wellTapBlock(datablock)).End().toByteArray(); final File fileToSave = new File(file.getParent(), fileNames[i]); if (!saveDataToFile(fileToSave, dataToSave)) return; } } } else { final FileNameDialog fileNameDialog = new FileNameDialog(this.mainFrame, "Save as " + baseName, null, new String[] { prepareNameForTAP(baseZXName, 0), prepareNameForTAP(baseZXName, 1), prepareNameForTAP(baseZXName, 2), prepareNameForTAP(baseZXName, 3) }, null); fileNameDialog.setVisible(true); if (fileNameDialog.approved()) { final String[] zxNames = fileNameDialog.getZxName(); final JBBPOut out = JBBPOut.BeginBin(); for (int i = 0; i < 4; i++) { final byte[] headerblock = makeHeaderBlock(zxNames[i], data.getInfo().getStartAddress(), data.length()); final byte[] datablock = makeDataBlock(data.getDataForCPU(i)); out.Byte(wellTapBlock(headerblock)).Byte(wellTapBlock(datablock)); } saveDataToFile(file, out.End().toByteArray()); } } }
From source file:DialogDemo.java
/** Creates the panel shown by the first tab. */ private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;//from ww w . ja va 2s . c om final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("OK (in the L&F's words)"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("Ewww!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("Me neither!"); } else { setLabel("Come on -- tell me!"); } // yes/no (not in those words) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No way!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("You're kidding!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("I don't like them, either."); } else { setLabel("Come on -- 'fess up!"); } // yes/no/cancel (not in those words) } else if (command == yncCommand) { Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like some green eggs to go " + "with that ham?", "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Here you go: green eggs and ham!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("OK, just the ham, then."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to eat them!"); } else { setLabel("Please tell me what you want!"); } } return; } }); return createPane(simpleDialogDesc + ":", radioButtons, showItButton); }
From source file:eu.apenet.dpt.standalone.gui.batch.ConvertAndValidateActionListener.java
public void actionPerformed(ActionEvent event) { labels = dataPreparationToolGUI.getLabels(); continueLoop = true;//from w w w . j a v a2 s . c om dataPreparationToolGUI.disableAllBtnAndItems(); dataPreparationToolGUI.disableEditionTab(); dataPreparationToolGUI.disableRadioButtons(); dataPreparationToolGUI.disableAllBatchBtns(); dataPreparationToolGUI.getAPEPanel().setFilename(""); final Object[] objects = dataPreparationToolGUI.getXmlEadList().getSelectedValues(); final ApexActionListener apexActionListener = this; new Thread(new Runnable() { public void run() { FileInstance uniqueFileInstance = null; String uniqueXslMessage = ""; int numberOfFiles = objects.length; int currentFileNumberBatch = 0; ProgressFrame progressFrame = new ProgressFrame(labels, parent, true, false, apexActionListener); JProgressBar batchProgressBar = progressFrame.getProgressBarBatch(); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().disableConversionBtn(); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().disableValidationBtn(); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().disableConvertAndValidateBtn(); dataPreparationToolGUI.getXmlEadList().setEnabled(false); for (Object oneFile : objects) { if (!continueLoop) { break; } File file = (File) oneFile; FileInstance fileInstance = dataPreparationToolGUI.getFileInstances().get(file.getName()); if (numberOfFiles == 1) { uniqueFileInstance = fileInstance; } if (!fileInstance.isXml()) { fileInstance.setXml(XmlChecker.isXmlParseable(file) == null); if (!fileInstance.isXml()) { if (type == CONVERT || type == CONVERT_AND_VALIDATE) { fileInstance.setConversionErrors(labels.getString("conversion.error.fileNotXml")); } else if (type == VALIDATE || type == CONVERT_AND_VALIDATE) { fileInstance.setValidationErrors(labels.getString("validation.error.fileNotXml")); } dataPreparationToolGUI.enableSaveBtn(); dataPreparationToolGUI.enableRadioButtons(); dataPreparationToolGUI.enableEditionTab(); } } SummaryWorking summaryWorking = new SummaryWorking(dataPreparationToolGUI.getResultArea(), batchProgressBar); summaryWorking.setTotalNumberFiles(numberOfFiles); summaryWorking.setCurrentFileNumberBatch(currentFileNumberBatch); Thread threadRunner = new Thread(summaryWorking); threadRunner.setName(SummaryWorking.class.toString()); threadRunner.start(); JProgressBar progressBar = null; Thread threadProgress = null; CounterThread counterThread = null; CounterCLevelCall counterCLevelCall = null; if (fileInstance.isXml()) { currentFileNumberBatch = currentFileNumberBatch + 1; if (type == CONVERT || type == CONVERT_AND_VALIDATE) { dataPreparationToolGUI.setResultAreaText(labels.getString("converting") + " " + file.getName() + " (" + (currentFileNumberBatch) + "/" + numberOfFiles + ")"); String eadid = ""; boolean doTransformation = true; if (fileInstance.getValidationSchema() .equals(Utilities.getXsdObjectFromPath(Xsd_enum.XSD_APE_SCHEMA.getPath())) || fileInstance.getValidationSchema().equals( Utilities.getXsdObjectFromPath(Xsd_enum.XSD_EAD_SCHEMA.getPath()))) { StaxTransformationTool staxTransformationTool = new StaxTransformationTool(file); staxTransformationTool.run(); LOG.debug("file has eadid? " + staxTransformationTool.isFileWithEadid()); if (!staxTransformationTool.isFileWithEadid()) { EadidQueryComponent eadidQueryComponent; if (staxTransformationTool.getUnitid() != null && !staxTransformationTool.getUnitid().equals("")) { eadidQueryComponent = new EadidQueryComponent( staxTransformationTool.getUnitid()); } else { eadidQueryComponent = new EadidQueryComponent(labels); } int result = JOptionPane.showConfirmDialog(parent, eadidQueryComponent.getMainPanel(), labels.getString("enterEADID"), JOptionPane.OK_CANCEL_OPTION); while (StringUtils.isEmpty(eadidQueryComponent.getEntryEadid()) && result != JOptionPane.CANCEL_OPTION) { result = JOptionPane.showConfirmDialog(parent, eadidQueryComponent.getMainPanel(), labels.getString("enterEADID"), JOptionPane.OK_CANCEL_OPTION); } if (result == JOptionPane.OK_OPTION) { eadid = eadidQueryComponent.getEntryEadid(); } else if (result == JOptionPane.CANCEL_OPTION) { doTransformation = false; } } } if (doTransformation) { int counterMax = 0; if (fileInstance.getConversionScriptName() .equals(Utilities.XSL_DEFAULT_APEEAD_NAME)) { progressBar = progressFrame.getProgressBarSingle(); progressBar.setVisible(true); progressFrame .setTitle(labels.getString("progressTrans") + " - " + file.getName()); CountCLevels countCLevels = new CountCLevels(); counterMax = countCLevels.countOneFile(file); if (counterMax > 0) { counterCLevelCall = new CounterCLevelCall(); counterCLevelCall.initializeCounter(counterMax); counterThread = new CounterThread(counterCLevelCall, progressBar, counterMax); threadProgress = new Thread(counterThread); threadProgress.setName(CounterThread.class.toString()); threadProgress.start(); } } try { try { File xslFile = new File(fileInstance.getConversionScriptPath()); File outputFile = new File(Utilities.TEMP_DIR + "temp_" + file.getName()); outputFile.deleteOnExit(); StringWriter xslMessages; HashMap<String, String> parameters = dataPreparationToolGUI.getParams(); parameters.put("eadidmissing", eadid); CheckIsEadFile checkIsEadFile = new CheckIsEadFile(file); checkIsEadFile.run(); if (checkIsEadFile.isEadRoot()) { File outputFile_temp = new File( Utilities.TEMP_DIR + ".temp_" + file.getName()); TransformationTool.createTransformation(FileUtils.openInputStream(file), outputFile_temp, Utilities.BEFORE_XSL_FILE, null, true, true, null, true, null); xslMessages = TransformationTool.createTransformation( FileUtils.openInputStream(outputFile_temp), outputFile, xslFile, parameters, true, true, null, true, counterCLevelCall); outputFile_temp.delete(); } else { xslMessages = TransformationTool.createTransformation( FileUtils.openInputStream(file), outputFile, xslFile, parameters, true, true, null, true, null); } fileInstance.setConversionErrors(xslMessages.toString()); fileInstance .setCurrentLocation(Utilities.TEMP_DIR + "temp_" + file.getName()); fileInstance.setConverted(); fileInstance.setLastOperation(FileInstance.Operation.CONVERT); uniqueXslMessage = xslMessages.toString(); if (xslMessages.toString().equals("")) { if (fileInstance.getConversionScriptName() .equals(Utilities.XSL_DEFAULT_APEEAD_NAME)) { fileInstance.setConversionErrors( labels.getString("conversion.noExcludedElements")); } else { fileInstance.setConversionErrors( labels.getString("conversion.finished")); } } if (!continueLoop) { break; } } catch (Exception e) { fileInstance.setConversionErrors(labels.getString("conversionException") + "\r\n\r\n-------------\r\n" + e.getMessage()); throw new Exception("Error when converting " + file.getName(), e); } if (threadProgress != null) { counterThread.stop(); threadProgress.interrupt(); } if (progressBar != null) { if (counterMax > 0) { progressBar.setValue(counterMax); } progressBar.setIndeterminate(true); } } catch (Exception e) { LOG.error("Error when converting and validating", e); } finally { summaryWorking.stop(); threadRunner.interrupt(); dataPreparationToolGUI.getXmlEadListLabel().repaint(); dataPreparationToolGUI.getXmlEadList().repaint(); if (progressBar != null) { progressBar.setVisible(false); } } } if (numberOfFiles == 1) { uniqueFileInstance = fileInstance; } } if (type == VALIDATE || type == CONVERT_AND_VALIDATE) { try { try { File fileToValidate = new File(fileInstance.getCurrentLocation()); InputStream is = FileUtils.openInputStream(fileToValidate); dataPreparationToolGUI .setResultAreaText(labels.getString("validating") + " " + file.getName() + " (" + currentFileNumberBatch + "/" + numberOfFiles + ")"); XsdObject xsdObject = fileInstance.getValidationSchema(); List<SAXParseException> exceptions; if (xsdObject.getName().equals(Xsd_enum.DTD_EAD_2002.getReadableName())) { exceptions = DocumentValidation.xmlValidationAgainstDtd( fileToValidate.getAbsolutePath(), Utilities.getUrlPathXsd(xsdObject)); } else { exceptions = DocumentValidation.xmlValidation(is, Utilities.getUrlPathXsd(xsdObject), xsdObject.isXsd11()); } if (exceptions == null || exceptions.isEmpty()) { fileInstance.setValid(true); fileInstance.setValidationErrors(labels.getString("validationSuccess")); if (xsdObject.getFileType().equals(FileInstance.FileType.EAD) && xsdObject.getName().equals("apeEAD")) { XmlQualityCheckerCall xmlQualityCheckerCall = new XmlQualityCheckerCall(); InputStream is2 = FileUtils .openInputStream(new File(fileInstance.getCurrentLocation())); TransformationTool.createTransformation(is2, null, Utilities.XML_QUALITY_FILE, null, true, true, null, false, xmlQualityCheckerCall); String xmlQualityStr = createXmlQualityString(xmlQualityCheckerCall); fileInstance.setValidationErrors( fileInstance.getValidationErrors() + xmlQualityStr); fileInstance.setXmlQualityErrors( createXmlQualityErrors(xmlQualityCheckerCall)); } } else { String errors = Utilities.stringFromList(exceptions); fileInstance.setValidationErrors(errors); fileInstance.setValid(false); } fileInstance.setLastOperation(FileInstance.Operation.VALIDATE); } catch (Exception ex) { fileInstance.setValid(false); fileInstance.setValidationErrors(labels.getString("validationException") + "\r\n\r\n-------------\r\n" + ex.getMessage()); throw new Exception("Error when validating", ex); } } catch (Exception e) { LOG.error("Error when validating", e); } finally { summaryWorking.stop(); threadRunner.interrupt(); dataPreparationToolGUI.getXmlEadListLabel().repaint(); dataPreparationToolGUI.getXmlEadList().repaint(); if (progressBar != null) { progressBar.setVisible(false); } } if (numberOfFiles == 1) { uniqueFileInstance = fileInstance; } } } } Toolkit.getDefaultToolkit().beep(); if (progressFrame != null) { try { progressFrame.stop(); } catch (Exception e) { LOG.error("Error when stopping the progress bar", e); } } dataPreparationToolGUI.getFinalAct().run(); if (numberOfFiles > 1) { dataPreparationToolGUI.getXmlEadList().clearSelection(); } else if (uniqueFileInstance != null) { if (type != VALIDATE) { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .setConversionErrorText(replaceGtAndLt(uniqueFileInstance.getConversionErrors())); if (uniqueXslMessage.equals("")) { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .checkFlashingTab(APETabbedPane.TAB_CONVERSION, Utilities.FLASHING_GREEN_COLOR); } else { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .checkFlashingTab(APETabbedPane.TAB_CONVERSION, Utilities.FLASHING_RED_COLOR); } } if (type != CONVERT) { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .setValidationErrorText(uniqueFileInstance.getValidationErrors()); if (uniqueFileInstance.isValid()) { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .checkFlashingTab(APETabbedPane.TAB_VALIDATION, Utilities.FLASHING_GREEN_COLOR); if (uniqueFileInstance.getValidationSchema() .equals(Utilities.getXsdObjectFromPath(Xsd_enum.XSD_APE_SCHEMA.getPath()))) { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().enableConversionEdmBtn(); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().enableValidationReportBtn(); } else if (uniqueFileInstance.getValidationSchema() .equals(Utilities.getXsdObjectFromPath(Xsd_enum.XSD_EAD_SCHEMA.getPath())) || uniqueFileInstance.getValidationSchema() .equals(Utilities.getXsdObjectFromPath(Xsd_enum.DTD_EAD_2002.getPath())) || uniqueFileInstance.getValidationSchema().equals( Utilities.getXsdObjectFromPath(Xsd_enum.XSD_EAC_SCHEMA.getPath()))) { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().enableConversionBtn(); // dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().enableValidationReportBtn(); } } else { dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .checkFlashingTab(APETabbedPane.TAB_VALIDATION, Utilities.FLASHING_RED_COLOR); if (uniqueFileInstance.getValidationSchema() .equals(Utilities.getXsdObjectFromPath(Xsd_enum.XSD_APE_SCHEMA.getPath())) || uniqueFileInstance.getValidationSchema().equals( Utilities.getXsdObjectFromPath(Xsd_enum.XSD_EAD_SCHEMA.getPath())) || uniqueFileInstance.getValidationSchema() .equals(Utilities.getXsdObjectFromPath(Xsd_enum.DTD_EAD_2002.getPath())) || uniqueFileInstance.getValidationSchema().equals( Utilities.getXsdObjectFromPath(Xsd_enum.XSD_APE_EAC_SCHEMA.getPath())) || uniqueFileInstance.getValidationSchema().equals( Utilities.getXsdObjectFromPath(Xsd_enum.XSD_EAC_SCHEMA.getPath()))) { dataPreparationToolGUI.enableConversionBtns(); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .enableConvertAndValidateBtn(); } } } dataPreparationToolGUI.enableMessageReportBtns(); } if (continueLoop) { dataPreparationToolGUI.setResultAreaText(labels.getString("finished")); } else { dataPreparationToolGUI.setResultAreaText(labels.getString("aborted")); } dataPreparationToolGUI.enableSaveBtn(); if (type == CONVERT) { dataPreparationToolGUI.enableValidationBtns(); } dataPreparationToolGUI.enableRadioButtons(); dataPreparationToolGUI.enableEditionTab(); } }).start(); }
From source file:be.fedict.eid.tsl.tool.TslTool.java
@Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (EXIT_ACTION_COMMAND.equals(command)) { System.exit(0);/* ww w . ja v a 2s.com*/ } else if (OPEN_ACTION_COMMAND.equals(command)) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Open TSL"); int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { displayTsl(fileChooser.getSelectedFile()); } } else if (ABOUT_ACTION_COMMAND.equals(command)) { JOptionPane.showMessageDialog(this, "eID TSL Tool\n" + "Copyright (C) 2009-2013 FedICT\n" + "http://code.google.com/p/eid-tsl/", "About", JOptionPane.INFORMATION_MESSAGE); } else if (CLOSE_ACTION_COMMAND.equals(command)) { if (this.activeTslInternalFrame.getTrustServiceList().hasChanged()) { int result = JOptionPane.showConfirmDialog(this, "TSL has been changed.\n" + "Save the TSL?", "Save", JOptionPane.YES_NO_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == result) { return; } if (JOptionPane.YES_OPTION == result) { try { this.activeTslInternalFrame.save(); } catch (IOException e) { LOG.error("IO error: " + e.getMessage(), e); } } } try { this.activeTslInternalFrame.setClosed(true); } catch (PropertyVetoException e) { LOG.warn("property veto error: " + e.getMessage(), e); } } else if (SIGN_ACTION_COMMAND.equals(command)) { LOG.debug("sign"); TrustServiceList trustServiceList = this.activeTslInternalFrame.getTrustServiceList(); if (trustServiceList.hasSignature()) { int confirmResult = JOptionPane.showConfirmDialog(this, "TSL is already signed.\n" + "Resign the TSL?", "Resign", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } SignSelectPkcs11FinishablePanel pkcs11Panel = new SignSelectPkcs11FinishablePanel(); WizardDescriptor wizardDescriptor = new WizardDescriptor( new WizardDescriptor.Panel[] { new SignInitFinishablePanel(), pkcs11Panel, new SignSelectCertificatePanel(pkcs11Panel, trustServiceList), new SignFinishFinishablePanel() }); wizardDescriptor.setTitle("Sign TSL"); wizardDescriptor.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); DialogDisplayer dialogDisplayer = DialogDisplayer.getDefault(); Dialog wizardDialog = dialogDisplayer.createDialog(wizardDescriptor); wizardDialog.setVisible(true); } else if (SAVE_ACTION_COMMAND.equals(command)) { LOG.debug("save"); try { this.activeTslInternalFrame.save(); this.saveMenuItem.setEnabled(false); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } } else if (SAVE_AS_ACTION_COMMAND.equals(command)) { LOG.debug("save as"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save As"); int result = fileChooser.showSaveDialog(this); if (JFileChooser.APPROVE_OPTION == result) { File tslFile = fileChooser.getSelectedFile(); if (tslFile.exists()) { int confirmResult = JOptionPane.showConfirmDialog(this, "File already exists.\n" + tslFile.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } try { this.activeTslInternalFrame.saveAs(tslFile); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } this.saveMenuItem.setEnabled(false); } } else if (EXPORT_ACTION_COMMAND.equals(command)) { LOG.debug("export"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Export to PDF"); int result = fileChooser.showSaveDialog(this); if (JFileChooser.APPROVE_OPTION == result) { File pdfFile = fileChooser.getSelectedFile(); if (pdfFile.exists()) { int confirmResult = JOptionPane.showConfirmDialog(this, "File already exists.\n" + pdfFile.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } try { this.activeTslInternalFrame.export(pdfFile); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } } } else if ("TSL-BE-2010-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.FIRST); displayTsl("*TSL-BE-2010-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2010-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.SECOND); displayTsl("*TSL-BE-2010-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2010-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.THIRD); displayTsl("*TSL-BE-2010-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.FIRST); displayTsl("*TSL-BE-2011-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.SECOND); displayTsl("*TSL-BE-2011-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.THIRD); displayTsl("*TSL-BE-2011-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.FIRST); displayTsl("*TSL-BE-2012-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.SECOND); displayTsl("*TSL-BE-2012-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.THIRD); displayTsl("*TSL-BE-2012-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.FIRST); displayTsl("*TSL-BE-2013-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.SECOND); displayTsl("*TSL-BE-2013-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.THIRD); displayTsl("*TSL-BE-2013-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.FIRST); displayTsl("*TSL-BE-2014-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.SECOND); displayTsl("*TSL-BE-2014-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.THIRD); displayTsl("*TSL-BE-2014-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.FIRST); displayTsl("*TSL-BE-2015-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.SECOND); displayTsl("*TSL-BE-2015-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.THIRD); displayTsl("*TSL-BE-2015-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } }
From source file:be.agiv.security.demo.Main.java
private void secConvCancelToken() { GridBagLayout gridBagLayout = new GridBagLayout(); GridBagConstraints gridBagConstraints = new GridBagConstraints(); JPanel contentPanel = new JPanel(gridBagLayout); JLabel urlLabel = new JLabel("URL:"); gridBagConstraints.gridx = 0;/*from w ww. j a v a 2 s . c o m*/ gridBagConstraints.gridy = 0; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.ipadx = 5; gridBagLayout.setConstraints(urlLabel, gridBagConstraints); contentPanel.add(urlLabel); JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_SC_LOCATION, 60); gridBagConstraints.gridx++; gridBagLayout.setConstraints(urlTextField, gridBagConstraints); contentPanel.add(urlTextField); int result = JOptionPane.showConfirmDialog(this, contentPanel, "Secure Conversation Cancel Token", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.CANCEL_OPTION) { return; } String location = urlTextField.getText(); SecureConversationClient secConvClient = new SecureConversationClient(location); try { secConvClient.cancelSecureConversationToken(this.secConvSecurityToken); this.secConvViewMenuItem.setEnabled(false); this.secConvCancelMenuItem.setEnabled(false); this.secConvSecurityToken = null; JOptionPane.showMessageDialog(this, "Secure conversation token cancelled.", "Secure Conversation", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { showException(e); } }