List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:org.gcaldaemon.gui.ConfigEditor.java
public final void info(String title, String message) { status(message);/*from ww w. ja v a 2s .co m*/ String[] options = new String[1]; options[0] = Messages.getString("ok"); //$NON-NLS-1$ JOptionPane.showOptionDialog(this, message, title, JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, null); }
From source file:org.gcaldaemon.gui.ConfigEditor.java
public final boolean question(String title, String message) { status(message);/* w ww.j a v a 2s .c o m*/ String[] options = new String[2]; options[0] = Messages.getString("ok"); //$NON-NLS-1$ options[1] = Messages.getString("cancel"); //$NON-NLS-1$ return (0 == JOptionPane.showOptionDialog(this, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null)); }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerSaveAsLayerToSLDAction.java
@Override public void actionPerformed(ActionEvent e) { boolean backup = false; File startWithFile = new File(System.getProperty("user.home"), styledLayer.getTitle().toString() + ".sld"); if (styledLayer.getSldFile() != null) startWithFile = styledLayer.getSldFile(); File exportFile = AsSwingUtil.chooseFileSave(owner, startWithFile, ASUtil.R("StyledLayerSLD.ChooseFileLocationDialog.Title"), new FileExtensionFilter(ASUtil.FILTER_SLD)); if (exportFile == null) return;//from w w w. j a v a2 s .c o m if (!(exportFile.getName().toLowerCase().endsWith(".sld") || exportFile.getName().toLowerCase().endsWith(".xml"))) { exportFile = new File(exportFile.getParentFile(), exportFile.getName() + ".sld"); } styledLayer.setSldFile(exportFile); if (styledLayer.getSldFile().exists()) { try { FileUtils.copyFile(styledLayer.getSldFile(), IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak")); backup = true; } catch (IOException e1) { LOGGER.warn("could not create a backup of the existing .sld", e1); return; } } try { StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile()); StylingUtil.saveStyleToSld(styledLayer.getStyle(), ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true, getOptimizedTitle(styledLayer)); Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"), ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") }; int dialogValue = 0; if (backup) { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } else { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } if (dialogValue == JOptionPane.NO_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(styledLayer.getSldFile()); } if (dialogValue == JOptionPane.CANCEL_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile())); } List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile())); if (es.size() > 0) { ExceptionDialog.show(owner, new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid", IOUtil.escapePath(styledLayer.getSldFile())), es.get(0))); } } catch (Exception e1) { LOGGER.error("saveStyleToSLD", e1); ExceptionDialog.show(owner, e1); return; } }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerSaveLayerToSLDAction.java
@Override public void actionPerformed(ActionEvent e) { boolean backup = false; if (styledLayer.getSldFile().exists()) { // if (StylingUtil.isStyleDifferent(styledLayer.getStyle(), // styledLayer.getSldFile())){ // return; // }/*from www .j a va 2s .c o m*/ try { FileUtils.copyFile(styledLayer.getSldFile(), IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak")); backup = true; } catch (IOException e1) { LOGGER.warn("could not create a backup of the existing .sld", e1); return; } } try { StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile()); StylingUtil.saveStyleToSld(styledLayer.getStyle(), ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true, "AtlasStyler " + ReleaseUtil.getVersionInfo(AtlasStyler.class) + ", Layer:" + styledLayer.getTitle() + ", Export-Mode: PRODUCTION"); Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"), ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") }; int dialogValue = 0; if (backup) { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } else { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } if (dialogValue == JOptionPane.NO_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(styledLayer.getSldFile()); } if (dialogValue == JOptionPane.CANCEL_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile())); } List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile())); if (es.size() > 0) { ExceptionDialog.show(owner, new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid", IOUtil.escapePath(styledLayer.getSldFile())), es.get(0))); } } catch (Exception e1) { LOGGER.error("saveStyleToSLD", e1); ExceptionDialog.show(owner, e1); return; } }
From source file:org.geworkbench.engine.ccm.CCMTableModel.java
/** * (non-Javadoc)//from w ww. j av a2s . c om * * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, * int, int, boolean) */ final boolean selectRow(Object value, int modelRow, boolean validation) { PluginComponent record = rows.get(modelRow); selected.put(record, (Boolean) value); Boolean currentChoice = (Boolean) getModelValueAt(modelRow, CCMTableModel.SELECTION_INDEX); List<String> required = record.getRequired(); List<String> related = record.getRelated(); String folder = resourceFolders.get(record); File file = files.get(record); List<String> unselectedRequired = new ArrayList<String>(); for (int i = 0; i < required.size(); i++) { String requiredClazz = required.get(i); Integer requiredRow = getModelRowByClazz(requiredClazz); Boolean requiredSelected = (Boolean) getModelValueAt(requiredRow.intValue(), CCMTableModel.SELECTION_INDEX); if (!requiredSelected) { unselectedRequired.add(requiredClazz); } } if (currentChoice.booleanValue()) { /* PLUGIN SELECTED */ String propFileName = null; String cwbFileName = file.getName(); if (cwbFileName.endsWith(".cwb.xml")) { propFileName = cwbFileName.replace(".cwb.xml", ".ccmproperties"); } else { log.error(".cwb.xml file is expected. Actual file name " + cwbFileName); } String licenseAccepted = ComponentConfigurationManager.readProperty(folder, propFileName, "licenseAccepted"); Boolean boolRequired = record.isMustAccept(); boolean bRequired = boolRequired.booleanValue(); if ((bRequired && (licenseAccepted == null)) || (bRequired && licenseAccepted != null && !licenseAccepted.equalsIgnoreCase("true"))) { String componentName = (String) getModelValueAt(modelRow, CCMTableModel.NAME_INDEX); String title = "Terms Acceptance"; String message = "\nBy clicking \"I Accept\", you signify that you \nhave read and accept the terms of the license \nagreement for the \"" + componentName + "\" application.\n\nTo view this license, exit out of this dialog and click \non the View License button below.\n\n"; Object[] options = { "I Accept", "No, thanks" }; int choice = JOptionPane.showOptionDialog(null, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (choice != 0) { ComponentConfigurationManager.writeProperty(folder, propFileName, "licenseAccepted", "false"); selected.put(record, new Boolean(false)); return false; } ComponentConfigurationManager.writeProperty(folder, propFileName, "licenseAccepted", "true"); } if (!validation) { fireTableDataChanged(); return true; } if (unselectedRequired.size() > 0 || related.size() > 0) { DependencyManager dmanager = new DependencyManager(this, unselectedRequired, modelRow, related); dmanager.checkDependency(); } } else { /* PLUGIN UNSELECTED */ List<Integer> dependentPlugins = null; String unselectedPluginClazz = "Plugin is missing a Class descriptor"; int unselectedRow = modelRow; if (unselectedRow >= 0) { unselectedPluginClazz = (String) getModelValueAt(unselectedRow, CCMTableModel.CLASS_INDEX); } dependentPlugins = new ArrayList<Integer>(); /* * Find Plugins that are dependent on this unselected plugin. */ int rowCount = getModelRowCount(); for (int i = 0; i < rowCount; i++) { /* * If the potentially dependent plugin is not selected, * don't bother to see if it is dependent */ Boolean selected = (Boolean) getModelValueAt(i, CCMTableModel.SELECTION_INDEX); if (!selected.booleanValue()) { continue; } List<String> requiredList = rows.get(i).getRequired(); for (int j = 0; j < requiredList.size(); j++) { String requiredClazz = requiredList.get(j); if (unselectedPluginClazz.equalsIgnoreCase(requiredClazz)) { dependentPlugins.add(new Integer(i)); break; } } } if (!validation) { fireTableDataChanged(); return true; } /* If dependencies are found, then popup a dialog */ if (dependentPlugins.size() > 0) { DependencyManager dmanager = new DependencyManager(this, dependentPlugins, modelRow); dmanager.checkDependency(); } } // fireTableCellUpdated(modelRow, column);//FIXME no use return true; }
From source file:org.gtdfree.GTDFree.java
/** * @param application/*from w w w . j ava 2 s .com*/ * @throws IOException */ private void checkForUpdates(boolean notifyOnSame) { VersionInfo[] v = null; VersionInfo current = new VersionInfo(getEngine().getConfiguration()); if (closed) { return; } try { v = getEngine().checkForNewVersions(current); } catch (IOException e1) { logger.error(Messages.getString("GTDFree.CheckFailed"), e1); //$NON-NLS-1$ return; } if (closed) { return; } if (v.length == 0) { if (notifyOnSame) { JOptionPane.showMessageDialog(getJFrame(), Messages.getString("GTDFree.UpToDate"), //$NON-NLS-1$ Messages.getString("GTDFree.UpdateCheck"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$ } } else { StringBuilder sb = new StringBuilder(); sb.append("<html><body><p>"); //$NON-NLS-1$ sb.append(Messages.getString("GTDFree.Update.1")); //$NON-NLS-1$ sb.append(" '"); //$NON-NLS-1$ sb.append(current.toFullVersionString()); sb.append("'. "); //$NON-NLS-1$ if (v.length == 1) { sb.append(Messages.getString("GTDFree.Update.2a")); //$NON-NLS-1$ } else { sb.append(Messages.getString("GTDFree.Update.2b")); //$NON-NLS-1$ } sb.append("</p><ul>"); //$NON-NLS-1$ for (int i = 0; i < v.length; i++) { sb.append("<li>'"); //$NON-NLS-1$ sb.append(v[i].toFullVersionString()); if (v[i].notes != null && v[i].notes.length() > 0) { sb.append("' "); //$NON-NLS-1$ sb.append(Messages.getString("GTDFree.Update.3")); //$NON-NLS-1$ sb.append("<br/>'"); //$NON-NLS-1$ sb.append(v[i].notes); } sb.append("'.</li>"); //$NON-NLS-1$ } sb.append("</ul></body></html>"); //$NON-NLS-1$ if (closed) { return; } int option = JOptionPane.showOptionDialog(getJFrame(), sb.toString(), Messages.getString("GTDFree.UpdateCheck"), //$NON-NLS-1$ JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { Messages.getString("GTDFree.VisitDL"), Messages.getString("GTDFree.Close") }, //$NON-NLS-1$ //$NON-NLS-2$ 0); if (closed) { System.exit(0); return; } if (option == 0) { try { Desktop.getDesktop().browse(new URI(getEngine().getConfiguration().getProperty("download.url", //$NON-NLS-1$ "http://gtd-free.sourceforge.net/download.html"))); //$NON-NLS-1$ } catch (Exception e) { logger.error(Messages.getString("GTDFree.LoadFailed"), e); //$NON-NLS-1$ } } } }
From source file:org.jajuk.base.Device.java
/** * Prepare manual refresh.//from ww w . j a v a 2 s .c om * * @param bAsk ask user to perform deep or fast refresh * * @return the user choice (deep or fast) * * @throws JajukException if user canceled, device cannot be refreshed or device already * refreshing */ int prepareRefresh(final boolean bAsk) throws JajukException { if (bAsk) { final Object[] possibleValues = { Messages.getString("FilesTreeView.60"), // fast Messages.getString("FilesTreeView.61"), // deep Messages.getString("Cancel") };// cancel try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { choice = JOptionPane.showOptionDialog(JajukMainWindow.getInstance(), Messages.getString("FilesTreeView.59"), Messages.getString("Option"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[0]); } }); } catch (Exception e) { Log.error(e); choice = Device.OPTION_REFRESH_CANCEL; } if (choice == Device.OPTION_REFRESH_CANCEL) { // Cancel return choice; } } // JajukException are not trapped, will be thrown to the caller final Device device = this; if (!device.isMounted()) { // Leave if user canceled device mounting if (!device.mount(true)) { return Device.OPTION_REFRESH_CANCEL; } } if (bAlreadyRefreshing) { throw new JajukException(107); } return choice; }
From source file:org.kepler.gui.kar.ImportModuleDependenciesAction.java
/** Check the dependencies and ask the user how to proceed. */ public ImportChoice checkDependencies() { ConfigurationManager cman = ConfigurationManager.getInstance(); ConfigurationProperty cprop = cman.getProperty(KARFile.KARFILE_CONFIG_PROP_MODULE); ConfigurationProperty KARComplianceProp = cprop.getProperty(KARFile.KAR_COMPLIANCE_PROPERTY_NAME); String KARCompliance = KARComplianceProp.getValue(); final ArrayList<String> dependencies = new ArrayList<String>(); try {/* w ww .jav a2s . c o m*/ if (_dependencies != null) { // dependencies were given dependencies.addAll(_dependencies); } else if (_archiveFile != null) { // kar file was given KARFile karFile = null; try { karFile = new KARFile(_archiveFile); dependencies.addAll(karFile.getModuleDependencies()); } finally { if (karFile != null) { karFile.close(); } } } else { // karxml was given dependencies.addAll(_karXml.getModuleDependencies()); } } catch (Exception ex) { ex.printStackTrace(); } //ModuleTree moduleTree = ModuleTree.instance(); //String currentModList = formattedCurrentModuleList(moduleTree); boolean dependencyMissingFullVersion = !(ModuleDependencyUtil .isDependencyVersioningInfoComplete(dependencies)); LinkedHashMap<String, Version> unsatisfiedDependencies = ModuleDependencyUtil .getUnsatisfiedDependencies(dependencies); String keplerRestartMessage = null; String unableToOpenOrExportInStrictKARComplianceMessage = null; String manualActionRequired = null; String unSats = formattedUnsatisfiedDependencies(unsatisfiedDependencies); final List<String> unSatsAsList = new ArrayList<String>(unsatisfiedDependencies.keySet()); String formattedDependencies = formatDependencies(dependencies); String htmlBGColor = "#" + Integer.toHexString(UIManager.getColor("OptionPane.background").getRGB() & 0x00ffffff); //XXX augment if additional strictness levels added if (KARCompliance.equals(KARFile.KAR_COMPLIANCE_STRICT)) { if (dependencyMissingFullVersion) { if (_exportMode) { unableToOpenOrExportInStrictKARComplianceMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR " + "lacks complete versioning information in its module-dependency list:<strong>" + formattedDependencies + "</strong><br><br>You must change your KAR opening compliance " + "preference to Relaxed before trying to export this KAR.<br><br>" + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>"; } else { unableToOpenOrExportInStrictKARComplianceMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR " + "lacks complete versioning information in its module-dependency list:<strong>" + formattedDependencies + "</strong><br><br>You must change your KAR opening compliance " + "preference to Relaxed before trying to open this KAR.<br><br>" + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>"; } } else { if (!unsatisfiedDependencies.isEmpty()) { if (_exportMode) { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">Your KAR opening compliance preference is set to Strict. To export this KAR in<br>" + "Strict mode you must restart Kepler with these additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to download (if necessary) and restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>" + "(re-enable using the Tools=>Module Manager...)</strong><br><br>" + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>"; } else { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">Your KAR opening compliance preference is set to Strict. To open this KAR in<br>" + "Strict mode you must restart Kepler with these additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to download (if necessary) and restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>" + "(re-enable using the Tools=>Module Manager...)</strong><br><br>" + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>"; } } else { if (_exportMode) { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">Your KAR opening compliance preference is set to Strict. To export this KAR in<br>" + "Strict mode you must restart Kepler using this module set in this order:<strong>" + formattedDependencies + "</strong><br><br>Would you like to restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>" + "(re-enable using the Tools=>Module Manager...)</strong><br><br>" + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>"; } else { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">Your KAR opening compliance preference is set to Strict. To open this KAR in<br>" + "Strict mode you must restart Kepler using this module set in this order:<strong>" + formattedDependencies + "</strong><br><br>Would you like to restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>" + "(re-enable using the Tools=>Module Manager...)</strong><br><br>" + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>"; } } } } else if (KARCompliance.equals(KARFile.KAR_COMPLIANCE_RELAXED)) { if (dependencyMissingFullVersion) { // if there's a dependency missing full version info, situation should be either 1) a 2.0 kar, in which case // it lacks the full mod dep list and so user must use MM, or 2) it's a 2.1 kar created from an svn // checkout of kepler, in which case, the power user should use the build system to // change to unreleased versions of a suite containing the required modules as necessary if (_exportMode) { manualActionRequired = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR " + "requires the following unsatisfied module dependencies that lack complete versioning information:<strong>" + unSats + "</strong><br><br>Please use the Module Manager or build system to change to a suite that uses these modules.</strong>" + "<br><br>You can Force Export, but some artifacts may not be included in the KAR.</body></html>"; } else { manualActionRequired = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR " + "requires the following unsatisfied module dependencies that lack complete versioning information:<strong>" + unSats + "</strong><br><br>Please use the Module Manager or build system to change to a suite that uses these modules.</strong>" + "<br><br>You can attempt a Force Open, but this may cause unexpected errors.</body></html>"; } } else { if (!unsatisfiedDependencies.isEmpty()) { if (_exportMode) { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR requires you restart Kepler with these " + "additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to " + "download (if necessary) and restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>" + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>"; } else { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR requires you restart Kepler with these " + "additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to " + "download (if necessary) and restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>" + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>"; } } else { //THIS SHOULDN'T HAPPEN log.error( "ImportModuleDependenciesAction WARNING unsatisfiedDependencies is empty, this shouldn't happen, but is non fatal"); if (_exportMode) { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR requires you restart Kepler with these " + "module(s):<strong>" + formattedDependencies + "</strong><br><br>Would you like to " + "restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>" + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>"; } else { keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR requires you restart Kepler with these " + "module(s):<strong>" + formattedDependencies + "</strong><br><br>Would you like to " + "restart Kepler using these modules now?" + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>" + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>"; } } } } String[] optionsOkForceopen = { "OK", "Force Open" }; String[] optionsOkForceexport = { "OK", "Force Export" }; String[] optionsYesNoForceopen = { "Yes", "No", "Force Open" }; String[] optionsYesNoForceexport = { "Yes", "No", "Force Export" }; if (unableToOpenOrExportInStrictKARComplianceMessage != null) { JLabel label = new JLabel(unableToOpenOrExportInStrictKARComplianceMessage); if (_exportMode) { int choice = JOptionPane.showOptionDialog(parent, label, "Unable to export in Strict mode", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceexport, optionsOkForceexport[0]); if (optionsOkForceexport[choice].equals("Force Export")) { return ImportChoice.FORCE_EXPORT; } } else { int choice = JOptionPane.showOptionDialog(parent, label, "Unable to open in Strict mode", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceopen, optionsOkForceopen[0]); if (optionsOkForceopen[choice].equals("Force Open")) { return ImportChoice.FORCE_OPEN; } } return ImportChoice.DO_NOTHING; } if (manualActionRequired != null) { JLabel label = new JLabel(manualActionRequired); if (_exportMode) { int choice = JOptionPane.showOptionDialog(parent, label, "Use Module Manager", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceexport, optionsOkForceexport[0]); if (optionsOkForceexport[choice].equals("Force Export")) { return ImportChoice.FORCE_EXPORT; } } else { int choice = JOptionPane.showOptionDialog(parent, label, "Use Module Manager", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceopen, optionsOkForceopen[0]); if (optionsOkForceopen[choice].equals("Force Open")) { return ImportChoice.FORCE_OPEN; } } return ImportChoice.DO_NOTHING; } JLabel label = new JLabel(keplerRestartMessage); if (_exportMode) { int choice = JOptionPane.showOptionDialog(parent, label, "Confirm Kepler Restart", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsYesNoForceexport, optionsYesNoForceexport[1]); if (optionsYesNoForceexport[choice] == "No") { // user doesn't want to download. return ImportChoice.DO_NOTHING; } else if (optionsYesNoForceexport[choice].equals("Force Export")) { return ImportChoice.FORCE_EXPORT; } } else { int choice = JOptionPane.showOptionDialog(parent, label, "Confirm Kepler Restart", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsYesNoForceopen, optionsYesNoForceopen[1]); if (optionsYesNoForceopen[choice] == "No") { // user doesn't want to download. return ImportChoice.DO_NOTHING; } else if (optionsYesNoForceopen[choice].equals("Force Open")) { return ImportChoice.FORCE_OPEN; } } parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() throws Exception { try { //download needed modules ModuleDownloader downloader = new ModuleDownloader(); ModuleDownloadProgressMonitor mdpm = new ModuleDownloadProgressMonitor(parent); downloader.addListener(mdpm); if (!unSatsAsList.isEmpty()) { downloader.downloadModules(unSatsAsList); } else { // this shouldn't happen, but if it does, resorting // to downloading all dependencies should be a safe bet log.error("ImportModuleDependenciesAction WARNING unSatsAsList is empty, " + "this shouldn't happen, but is non fatal"); downloader.downloadModules(dependencies); } //rewrite modules.txt ModulesTxt modulesTxt = ModulesTxt.instance(); modulesTxt.clear(); for (String dependency : dependencies) { //System.out.println("ImportModuleDependency doInBackground modulesTxt.add("+dependency+")"); modulesTxt.add(dependency); } modulesTxt.write(); //delete and write "unknown" to current-suite.txt CurrentSuiteTxt.delete(); CurrentSuiteTxt.setName("unknown"); // if KARCompliance is Strict, user is restarting w/ specific versions of modules // and we don't want them to potentially auto update on restart to available patches turnOffAutoUpdatesIfStrictMode(); //restart Kepler using new modules spawnNewKeplerAndQuitCurrent(); return null; } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(parent, "Error downloading module: " + ex.getMessage()); return null; } } @Override protected void done() { //never reached. } }; worker.execute(); parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return ImportChoice.DOWNLOADING_AND_RESTARTING; }
From source file:org.kepler.gui.KeplerGraphFrame.java
/** * Open a dialog to prompt the user to save a KAR. Return false if the user * clicks "cancel", and otherwise return true. * // www .j a v a2 s . c o m * Overrides Top._queryForSave() * * @return _SAVED if the file is saved, _DISCARDED if the modifications are * discarded, _CANCELED if the operation is canceled by the user, * and _FAILED if the user selects save and the save fails. */ @Override protected int _queryForSave() { Object[] options = { "Save", "Discard changes", "Cancel" }; // making more generic since other items to go in the KAR // may be the reason for querying to save // String query = "Save changes to " + StringUtilities.split(_getName()) // + "?"; String query = "Save changes to KAR?"; // Show the MODAL dialog int selected = JOptionPane.showOptionDialog(this, query, "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (selected == JOptionPane.YES_OPTION) { JButton saveButton = new JButton("Save Kar"); ExportArchiveAction eaa = new ExportArchiveAction(this); eaa.setRefreshFrameAfterSave(false); // if the file already exists, call ExportArchiveAction.setSave() // so that the save as file dialog does is not used. KARFile karFile = KARManager.getInstance().get(this); if (karFile != null) { File file = karFile.getFileLocation(); if (file.canWrite()) { eaa.setSaveFile(file); } } saveButton.addActionListener(eaa); saveButton.doClick(); if (eaa.saveSucceeded()) { setModified(false); return _SAVED; } else { return _FAILED; } } if (selected == JOptionPane.NO_OPTION) { return _DISCARDED; } return _CANCELED; }
From source file:org.modelibra.util.FileSelector.java
/** * Prompts a user to decide if the file should be replaced: yes or no. * /*from w w w . j av a 2 s.co m*/ * @param parentFrame * parent window * @param lang * language * @return <code>true</code> if a user chooses yes */ public boolean replaceFile(JFrame parentFrame, NatLang lang) { // Custom button text Object[] options = { lang.getText("yes"), lang.getText("no") }; JOptionPane.setDefaultLocale(lang.getLocale()); int response = JOptionPane.showOptionDialog(parentFrame, // parent // frame lang.getText("replaceFile"), // message lang.getText("fileExists"), // title JOptionPane.YES_NO_OPTION, // option type JOptionPane.QUESTION_MESSAGE, // message type null, // don't use a custom icon options, // the titles of buttons options[0]); // default button title if (response == JOptionPane.NO_OPTION) { return false; } return true; }