Java Code Examples for javax.swing.JOptionPane#CLOSED_OPTION

The following examples show how to use javax.swing.JOptionPane#CLOSED_OPTION . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private boolean showRetryDialog() {
  int dialogSelection
      = JOptionPane.showConfirmDialog(null,
                                      BUNDLE.getString("defaultServiceCallWrapper.optionPane_retryConfirmation.message"),
                                      BUNDLE.getString("defaultServiceCallWrapper.optionPane_retryConfirmation.title"),
                                      JOptionPane.YES_NO_CANCEL_OPTION);

  switch (dialogSelection) {
    case JOptionPane.YES_OPTION:
      // Only retry if we connected successfully
      return portalManager.connect(PortalManager.ConnectionMode.RECONNECT);
    case JOptionPane.NO_OPTION:
      return false;
    case JOptionPane.CANCEL_OPTION:
      application.offline();
      return false;
    case JOptionPane.CLOSED_OPTION:
      return false;
    default:
      return false;
  }
}
 
Example 2
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	final AnalysisKickOff akf = new AnalysisKickOff();
	IEditorPart openEditor = UIUtils.getCurrentlyOpenEditor();

	// check if there are unsaved changes
	if (openEditor != null && openEditor.isDirty()) {
		int answr = saveFile(Utils.getCurrentlyOpenFile());
		// save file and analyze
		if (answr == JOptionPane.YES_OPTION) {
			openEditor.doSave(null);
		}
		// no analyze no save file
		else if (answr == JOptionPane.CLOSED_OPTION) {
			return null;
		}
	}
	if (akf.setUp(JavaCore.create(Utils.getCurrentlySelectedIProject()))) {
		akf.run();
	}
	return null;
}
 
Example 3
Source Project: appinventor-extensions   File: AIMerger.java    License: Apache License 2.0 6 votes vote down vote up
private void offerNewMerge() {
  int response = JOptionPane.showOptionDialog(myCP, "Projects Successfully Merged. "
          + "Would you like to merge more projects?", "Projects Merged", JOptionPane.YES_NO_OPTION,
      JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.NO_OPTION:
      closeApplication();
      break;
    case JOptionPane.YES_OPTION:
      offerToMergeToNewProject();
      break;
  }
}
 
Example 4
Source Project: appinventor-extensions   File: AIMerger.java    License: Apache License 2.0 6 votes vote down vote up
private void offerToMergeToNewProject() {
  int response = JOptionPane.showOptionDialog(myCP, "Would you like one of the projects to merge"
          + " to be the project you just created?", "Merge More Projects", JOptionPane.YES_NO_OPTION,
      JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
      closeApplication();
      break;
    case JOptionPane.NO_OPTION:
      resetAIMerger(null);
      break;
    case JOptionPane.YES_OPTION:
      resetAIMerger(mergeProjectPath);
      break;
  }
}
 
Example 5
Source Project: appinventor-extensions   File: AIMerger.java    License: Apache License 2.0 6 votes vote down vote up
private void offerNewMerge() {
  int response = JOptionPane.showOptionDialog(myCP, "Projects Successfully Merged. "
      + "Would you like to merge more projects?", "Projects Merged", JOptionPane.YES_NO_OPTION,
      JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.NO_OPTION:
      closeApplication();
      break;
    case JOptionPane.YES_OPTION:
      offerToMergeToNewProject();
      break;
  }
}
 
Example 6
Source Project: pgptool   File: UiUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param messageType
 *            one of the JOptionPane ERROR_MESSAGE, INFORMATION_MESSAGE,
 *            WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
 */
public static void messageBox(ActionEvent originEvent, String msg, String title, int messageType) {
	Object content = buildMessageContentDependingOnLength(msg);

	Component parent = findWindow(originEvent);
	if (messageType != JOptionPane.ERROR_MESSAGE) {
		JOptionPane.showMessageDialog(parent, content, title, messageType);
		return;
	}

	Object[] options = { text("action.ok"), text("phrase.saveMsgToFile") };
	if ("action.ok".equals(options[0])) {
		// if app context wasn't started MessageSource wont be available
		options = new String[] { "OK", "Save message to file" };
	}

	int result = JOptionPane.showOptionDialog(parent, content, title, JOptionPane.YES_NO_OPTION, messageType, null,
			options, JOptionPane.YES_OPTION);
	if (result == JOptionPane.YES_OPTION || result == JOptionPane.CLOSED_OPTION) {
		return;
	}

	// Save to file
	saveMessageToFile(parent, msg);
}
 
Example 7
private static int optionOf (JOptionPane pane)
{
    Object selectedValue = pane.getValue();

    if (selectedValue == null) {
        return JOptionPane.CLOSED_OPTION;
    } else if (selectedValue instanceof Integer) {
        return ((Integer) selectedValue).intValue();
    } else {
        return JOptionPane.CLOSED_OPTION;
    }
}
 
Example 8
public static int showDialog(String message, int messageType){

		int optionType = JOptionPane.DEFAULT_OPTION;
		String title = null;
		
		if (messageType == JOptionPane.ERROR_MESSAGE){
			title = "Error ";
			optionType = JOptionPane.DEFAULT_OPTION;
		}else if (messageType == JOptionPane.QUESTION_MESSAGE){
			title = "Confirm ";
			optionType = JOptionPane.YES_NO_OPTION;
		}
		else if (messageType == JOptionPane.INFORMATION_MESSAGE){
			title = "Information ";
			optionType = JOptionPane.DEFAULT_OPTION;
		}
		
		JOptionPane pane = new JOptionPane(message, messageType, optionType);
		
		JDialog dialog = pane.createDialog(pane, title);
		
		UIUtil.applyOptionPaneBackground(pane,UIConsts.OPTIONPANE_BACKGROUND);
		
		dialog.setVisible(true);
		
		Object selectedValue = pane.getValue();
	    if(selectedValue instanceof Integer) {
	    	return ((Integer)selectedValue).intValue();
		}
	    return JOptionPane.CLOSED_OPTION;
	}
 
Example 9
Source Project: wpcleaner   File: TaskYesNoAllDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
  Object[] options = new Object[] {
      GT._T("Yes"),
      GT._T("Yes to all"),
      GT._T("No"),
      GT._T("No to all"),
  }; 
  JOptionPane pane = new JOptionPane(
      message, JOptionPane.WARNING_MESSAGE,
      JOptionPane.YES_NO_OPTION, null, options);
  JDialog dialog = pane.createDialog(parent, Version.PROGRAM);
  dialog.setVisible(true);
  Object selectedValue = pane.getValue();
  if (selectedValue == null) {
    result = JOptionPane.CLOSED_OPTION;
  } else if (options[0].equals(selectedValue)) {
    result = JOptionPane.YES_OPTION;
  } else if (options[1].equals(selectedValue)) {
    result = Utilities.YES_ALL_OPTION;
  } else if (options[2].equals(selectedValue)) {
    result = JOptionPane.NO_OPTION;
  } else if (options[3].equals(selectedValue)) {
    result =  Utilities.NO_ALL_OPTION;
  } else {
    result = JOptionPane.CLOSED_OPTION;
  }
}
 
Example 10
/**
 * Close the supplied KeyStore. Allow the user to save it if there are
 * unsaved changes.
 *
 * @param history
 *            KeyStore history
 * @return True if the KeyStore is closed, false otherwise
 */
public boolean closeKeyStore(KeyStoreHistory history) {
	KeyStoreState currentState = history.getCurrentState();

	if (needSave(currentState)) {
		kseFrame.focusOnKeyStore(currentState.getKeyStore());

		int wantSave = wantSave(history);

		if (wantSave == JOptionPane.YES_OPTION) {
			boolean saved = saveKeyStore(history);

			if (!saved) {
				return false;
			}

			// Current state may have changed with the addition of a
			// KeyStore password during
			// save
			currentState = history.getCurrentState();
		} else if ((wantSave == JOptionPane.CANCEL_OPTION) || (wantSave == JOptionPane.CLOSED_OPTION)) {
			return false;
		}
	}

	kseFrame.removeKeyStore(currentState.getKeyStore());
	kseFrame.updateControls(true);

	return true;
}
 
Example 11
Source Project: wpcleaner   File: TaskYesNoAllDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Result.
 */
public int getResult() {
  if (result != null) {
    return result.intValue();
  }
  return JOptionPane.CLOSED_OPTION;
}
 
Example 12
Source Project: wpcleaner   File: TaskConfirmDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Result.
 */
public int getResult() {
  if (result != null) {
    return result.intValue();
  }
  return JOptionPane.CLOSED_OPTION;
}
 
Example 13
/**
	 * Cancels the currently selected transport item.
	 */
	private void cancelTransportItem() {
		String msg = "Note: you have highlighted a mission on the top-left box 'Incoming Transport Items' and clicked on the 'Discard Mission' button.";

//		if (mainScene != null) {
//			Platform.runLater(() -> {
//				askFX(msg);
//			});
//		}
//		else {
			// Add a dialog box asking the user to confirm "discarding" the mission
			JDialog.setDefaultLookAndFeelDecorated(true);
			final int response = JOptionPane.showConfirmDialog(null, msg, "Confirm",
					JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
			if (response == JOptionPane.NO_OPTION) {
				// "No" button click, do nothing
			} else if (response == JOptionPane.YES_OPTION) {
				// "Yes" button clicked and go ahead with discarding this mission
				Transportable transportItem = (Transportable) incomingListPane.getIncomingList().getSelectedValue();
				if (transportItem != null) {
					// call cancelTransportItem() in TransportManager Class to cancel the selected transport item.
					Simulation.instance().getTransportManager().cancelTransportItem(transportItem);
				}
			} else if (response == JOptionPane.CLOSED_OPTION) {
				// Close the dialogbox, do nothing
			}
//		}
	}
 
Example 14
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 15
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 16
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 17
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 18
Source Project: iBioSim   File: SBOLField2.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Run dialog to ask user if they want to associate SBOL from parts registry or create a generic part.
 * @param filePath - the full path to the SBOL file.
 * @throws Exception - SBOL data exception
 */
private void associateSBOL(String filePath, SBOLDocument workingDoc)
{
	//TODO: Add check to perform SBOL association for CompDef and ModDef
	String[] options = {"Registry part", "Generic part", "Cancel"};
	int choice = JOptionPane.showOptionDialog(getParent(),
			"There is currently no associated SBOL part.  Would you like to associate one from a registry or associate a generic part?",
			"Associate SBOL Part", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
			options[0]);

	switch (choice) {

	case 0: // Registry Part
		SBOLDocument selection = new RegistryInputDialog(Gui.frame, RegistryInputDialog.ALL_PARTS,
				edu.utah.ece.async.sboldesigner.sbol.SBOLUtils.Types.All_types, null, workingDoc).getInput();

		if (selection != null) 
		{
			try 
			{
				SBOLUtils.insertTopLevels(selection, workingDoc);
			} 
			catch (Exception e) 
			{
				JOptionPane.showMessageDialog(getParent(), "Unable associate SBOL with this object", 
						"Failed Associating SBOL",
						JOptionPane.ERROR_MESSAGE);
				e.printStackTrace();
			}
			ComponentDefinition associated_compDef = selection.getRootComponentDefinitions().iterator().next();
			setAssociatedSBOL(filePath, workingDoc, associated_compDef);
		}
		break;

	case 1: // Generic Part
		ComponentDefinition cd = Parts.GENERIC.createComponentDefinition(workingDoc);
		setAssociatedSBOL(filePath, workingDoc, cd);
		editSBOL(filePath, workingDoc);
		break;

	case JOptionPane.CLOSED_OPTION:
	default:
	}
}
 
Example 19
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 20
Source Project: gcs   File: RowEditor.java    License: Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Brings up a modal detailed editor for each row in the list.
 *
 * @param owner The owning component.
 * @param list  The rows to edit.
 * @return Whether anything was modified.
 */
@SuppressWarnings("unused")
public static boolean edit(Component owner, List<? extends ListRow> list) {
    ArrayList<RowUndo> undos = new ArrayList<>();
    ListRow[]          rows  = list.toArray(new ListRow[0]);

    int length = rows.length;
    for (int i = 0; i < length; i++) {
        boolean                      hasMore = i != length - 1;
        ListRow                      row     = rows[i];
        RowEditor<? extends ListRow> editor  = row.createEditor();
        String                       title   = MessageFormat.format(I18n.Text("Edit {0}"), row.getRowType());
        JPanel                       wrapper = new JPanel(new BorderLayout());

        if (hasMore) {
            int    remaining = length - i - 1;
            String msg       = remaining == 1 ? I18n.Text("1 item remaining to be edited.") : MessageFormat.format(I18n.Text("{0} items remaining to be edited."), Integer.valueOf(remaining));
            JLabel panel     = new JLabel(msg, SwingConstants.CENTER);
            panel.setBorder(new EmptyBorder(0, 0, 10, 0));
            wrapper.add(panel, BorderLayout.NORTH);
        }
        wrapper.add(editor, BorderLayout.CENTER);

        int      type       = hasMore ? JOptionPane.YES_NO_CANCEL_OPTION : JOptionPane.YES_NO_OPTION;
        String   applyText  = I18n.Text("Apply");
        String   cancelText = I18n.Text("Cancel");
        String[] options    = hasMore ? new String[]{applyText, cancelText, I18n.Text("Cancel Remaining")} : new String[]{applyText, cancelText};
        switch (WindowUtils.showOptionDialog(owner, wrapper, title, true, type, JOptionPane.PLAIN_MESSAGE, null, options, applyText)) {
        case JOptionPane.YES_OPTION:
            RowUndo undo = new RowUndo(row);
            if (editor.applyChanges()) {
                if (undo.finish()) {
                    undos.add(undo);
                }
            }
            break;
        case JOptionPane.NO_OPTION:
            break;
        case JOptionPane.CANCEL_OPTION:
        case JOptionPane.CLOSED_OPTION:
        default:
            i = length;
            break;
        }
        editor.finished();
    }

    if (!undos.isEmpty()) {
        new MultipleRowUndo(undos);
        return true;
    }
    return false;
}