Java Code Examples for docking.widgets.OptionDialog#showYesNoDialogWithNoAsDefaultButton()

The following examples show how to use docking.widgets.OptionDialog#showYesNoDialogWithNoAsDefaultButton() . 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 check out the related API usage on the sidebar.
Example 1
Source File: DeleteAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	int choice = OptionDialog.showYesNoDialogWithNoAsDefaultButton(null,
		"Confirm Delete Operation", "Are you sure you want to delete selected\n categories " +
			"and/or dataTypes?\n(Note: There is no undo for archives.)");
	if (choice != OptionDialog.OPTION_ONE) {
		return;
	}

	GTree gtree = (GTree) context.getContextObject();
	TreePath[] selectionPaths = gtree.getSelectionPaths();
	List<GTreeNode> nodeList = new ArrayList<>(selectionPaths.length);
	for (TreePath path : selectionPaths) {
		nodeList.add((GTreeNode) path.getLastPathComponent());
	}
	plugin.getTool().execute(new DataTypeTreeDeleteTask(plugin, nodeList), 250);
}
 
Example 2
Source File: MergeManagerProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void cancelCallback(boolean force) {

		boolean cancel = force;
		if (!force) {
			int choice =
				OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "Confirm Cancel Merge",
					"Warning!  Cancel causes the entire merge process to be canceled.\n" +
						"Do you want to cancel the Merge Process?");
			cancel = choice == OptionDialog.OPTION_ONE;
		}

		if (cancel) {
			wasCanceled = true;
			MergeManager mergeManager = plugin.getMergeManager();
			if (mergeManager != null) {
				mergeManager.cancel();
			}
		}
	}
 
Example 3
Source File: ArchiveUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
static File getFile(Component component, FileArchive archive) {
	ArchiveFileChooser fileChooser = new ArchiveFileChooser(component);
	String archiveName = archive.getName();
	File file = fileChooser.promptUserForFile(archiveName);

	if (file == null) {
		return null;
	}
	if (file.equals(archive.getFile())) {
		return file;
	}

	if (archive.getArchiveManager().isInUse(file)) {
		Msg.showInfo(ArchiveUtils.class, component, "Cannot Perform Save As",
			"Cannot save archive to " + file.getName() + "\nbecause " + file.getName() +
				" is in use.");
		return null;
	}

	if (file.exists()) {
		if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(component,
			"Overwrite Existing File?", "Do you want to overwrite existing file\n" +
				file.getAbsolutePath()) != OptionDialog.OPTION_ONE) {
			return null;
		}

		if (!deleteArchiveFile(file)) {
			Msg.showError(log, component, "Error Deleting File",
				"Could not delete file " + file.getAbsolutePath());

			return null;
		}
	}

	return file;
}
 
Example 4
Source File: CreateArchiveAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	DataTypeArchiveGTree gTree = plugin.getProvider().getGTree();
	ArchiveFileChooser fileChooser = new ArchiveFileChooser(gTree);
	fileChooser.setApproveButtonText("Create Archive");
	fileChooser.setApproveButtonToolTipText("Create Archive");
	fileChooser.setTitle("Create Archive");

	Msg.trace(this, "Showing filechooser to get new archive name...");
	File file = fileChooser.promptUserForFile("New_Archive");
	if (file == null) {
		Msg.trace(this, "No new archive filename chosen by user - not performing action");
		return;
	}

	Msg.trace(this, "User picked file: " + file.getAbsolutePath());

	if (file.exists()) {
		Msg.trace(this, "Need to overwrite--showing dialog");
		if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(gTree,
			"Overwrite Existing File?",
			"Do you want to overwrite existing file\n" +
				file.getAbsolutePath()) != OptionDialog.OPTION_ONE) {
			Msg.trace(this, "\tdo not overwrite was chosen");
			return;
		}
		Msg.trace(this, "\toverwriting file!");
		file.delete();
	}
	Archive newArchive = plugin.getDataTypeManagerHandler().createArchive(file);
	if (newArchive != null) {
		Msg.trace(this, "Created new archive: " + newArchive.getName());
		selectNewArchive(newArchive, gTree);
	}
}
 
Example 5
Source File: EnumEditorPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
void domainObjectRestored(DataTypeManagerDomainObject domainObject, EnumDataType enuum) {

		stopCellEditing();
		this.originalEnumDT = enuum;
		this.editedEnumDT = (EnumDataType) enuum.copy(enuum.getDataTypeManager());
		DataTypeManager objectDataTypeManager = domainObject.getDataTypeManager();
		DataTypeManager providerDataTypeManager = provider.getDataTypeManager();
		if (objectDataTypeManager != providerDataTypeManager) {
			return; // The editor isn't associated with the restored domain object.
		}
		String objectType = "domain object";
		if (domainObject instanceof Program) {
			objectType = "program";
		}
		else if (domainObject instanceof DataTypeArchive) {
			objectType = "data type archive";
		}
		if (tableModel.hasChanges()) {
			if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(this, "Reload Enum Editor?",
				"The " + objectType + " \"" + objectDataTypeManager.getName() +
					"\" has been restored.\n" + "\"" + tableModel.getEnum().getDisplayName() +
					"\" may have changed outside this editor.\n" +
					"Do you want to discard edits and reload the Enum?") == OptionDialog.OPTION_TWO) {

				// no
				categoryField.setText(provider.getCategoryText());
				return; // Don't reload.
			}
		}
		// Reloading the enum.
		setFieldInfo(editedEnumDT);
		tableModel.setEnum(editedEnumDT, false);
	}
 
Example 6
Source File: VersionControlCheckOutAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private boolean gatherVersionedFiles(TaskMonitor monitor, List<DomainFile> results)
		throws CancelledException {

	monitor.setMessage("Examining Files...");
	monitor.setMaximum(files.size());

	for (DomainFile df : files) {
		monitor.checkCanceled();

		if (df.isVersioned() && !df.isCheckedOut()) {
			results.add(df);
		}
		monitor.incrementProgress(1);
	}

	int n = results.size();
	if (n == 0) {
		Msg.showError(this, tool.getToolFrame(), "Checkout Failed",
			"The specified files do not contain any versioned files available for " +
				"checkeout");
		return false;
	}

	//
	// Confirm checkout - prompt for exclusive checkout, if possible.  Otherwise, only
	//                    confirm a bulk checkout.
	//

	// note: a 'null' user means that we are using a local repository
	User user = getUser();
	if (user != null && user.hasWritePermission()) {
		CheckoutDialog checkout = new CheckoutDialog();
		if (checkout.showDialog(tool) != CheckoutDialog.OK) {
			return false;
		}
		exclusive = checkout.exclusiveCheckout();
		return true;
	}

	if (n == 1) {
		return true; // single file; no prompt needed
	}

	// more than one file
	int choice = OptionDialog.showYesNoDialogWithNoAsDefaultButton(tool.getToolFrame(),
		"Confirm Bulk Checkout",
		"Would you like to checkout " + results.size() + " files as specified?");
	return choice == OptionDialog.YES_OPTION;
}
 
Example 7
Source File: StackEditorPanel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
	public void domainObjectRestored(DataTypeManagerDomainObject domainObject) {
		boolean reload = true;
		String objectType = "domain object";
		if (domainObject instanceof Program) {
			objectType = "program";
		}
		else if (domainObject instanceof DataTypeArchive) {
			objectType = "data type archive";
		}
		DataTypeManager dtm = ((StackEditorModel) model).getOriginalDataTypeManager();
		Composite originalDt = ((StackEditorModel) model).getOriginalComposite();
		if (originalDt instanceof StackFrameDataType) {
			StackFrameDataType sfdt = (StackFrameDataType) originalDt;
			Function function = sfdt.getFunction();
			if (function instanceof DatabaseObject) {
				if (!((DatabaseObject) function).checkIsValid()) {
					// Cancel Editor.
					provider.dispose();
					PluginTool tool = ((StackEditorProvider) provider).getPlugin().getTool();
					tool.setStatusInfo("Stack Editor was closed for " + provider.getName());
					return;
				}
			}
			StackFrame stack = function.getStackFrame();
			StackFrameDataType newSfdt = new StackFrameDataType(stack, dtm);
			if (!newSfdt.equals(((StackEditorModel) model).getViewComposite())) {
				originalDt = newSfdt;
			}
		}
		((StackEditorModel) model).updateAndCheckChangeState();
		if (model.hasChanges()) {
			String name = ((StackEditorModel) model).getTypeName();
			// The user has modified the structure so prompt for whether or
			// not to reload the structure.
			String question =
				"The " + objectType + " \"" + domainObject.getName() + "\" has been restored.\n" +
					"\"" + model.getCompositeName() + "\" may have changed outside the editor.\n" +
					"Discard edits & reload the " + name + " Editor?";
			String title = "Reload " + name + " Editor?";
			int response = OptionDialog.showYesNoDialogWithNoAsDefaultButton(this, title, question);
			if (response != 1) {
				reload = false;
			}
		}
		if (reload) {
			cancelCellEditing();
			// TODO
//			boolean lockState = model.isLocked(); // save the lock state
			model.load(originalDt, model.isOffline()); // reload the structure
//			model.setLocked(lockState); // restore the lock state
			model.updateAndCheckChangeState();
		}
		else {
			((StackEditorModel) model).refresh();
		}
	}
 
Example 8
Source File: CompEditorModel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void dataTypeChanged(DataTypeManager dtm, DataTypePath path) {
	try {

		if (isLoaded()) {
			// If we don't currently have any modifications that need applying and
			// the structure in the editor just changed, then show the changed
			// structure.
			if (originalDataTypePath == null) {
				return;
			}
			String oldName = path.getDataTypeName();
			if (path.equals(originalDataTypePath)) {
				if (consideringReplacedDataType) {
					return;
				}
				// Return if the original is already changing. Need this since there
				// can be multiple change notifications from a single data type update 
				// event due to replaceWith(), setLastChangeTime() and 
				// setLastChangeTimeInSource() each firing dataTypeChanged().
				if (originalIsChanging) {
					return;
				}
				originalIsChanging = true;
				try {
					if (hadChanges) {
						String message = "<html>" + HTMLUtilities.escapeHTML(oldName) +
							" has changed outside the editor.<br>" +
							"Discard edits & reload the " + getTypeName() + "?";
						String title = "Reload " + getTypeName() + " Editor?";
						int response = OptionDialog.showYesNoDialogWithNoAsDefaultButton(
							provider.getComponent(), title, message);
						if (response == OptionDialog.OPTION_ONE) {
							load(getOriginalComposite());
						}
						originalComponentsChanged();
					}
					else {
						Composite changedComposite = getOriginalComposite();
						if ((changedComposite != null) &&
							!viewComposite.isEquivalent(changedComposite)) {
							load(getOriginalComposite());
							setStatus(
								viewComposite.getPathName() + " changed outside the editor.",
								false);
						}
					}
				}
				finally {
					originalIsChanging = false;
				}
			}
			else {
				DataType viewDt = viewDTM.getDataType(path);
				if (viewDt == null) {
					return;
				}
				int origDtLen = viewDt.getLength();
				DataType changedDt = dtm.getDataType(path);
				if (changedDt != null) {
					if ((viewDt instanceof Composite) && (changedDt instanceof Composite)) {
						Composite comp = (Composite) changedDt;
						Composite origDt = getOriginalComposite();
						if ((origDt != null) && comp.isPartOf(origDt)) {
							removeDtFromComponents(comp);
						}

						((Composite) viewDt).setDescription(
							((Composite) changedDt).getDescription());
					}
					viewDt =
						viewDTM.resolve(changedDt, DataTypeConflictHandler.REPLACE_HANDLER);
					if (origDtLen != viewDt.getLength()) {
						viewComposite.dataTypeSizeChanged(viewDt);
					}
				}
				fireTableDataChanged();
				componentDataChanged();
			}
		}
	}
	catch (ConcurrentModificationException e) {
		// do nothing, the delete will fix things later
	}
}
 
Example 9
Source File: CompEditorPanel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void updatedStructureSize() {

		if (updatingSize) {
			return;
		}
		if (!sizeStatusTextField.isShowing()) {
			return;
		}

		if (!((CompEditorModel) model).isSizeEditable()) {
			return;
		}

		String valueStr = sizeStatusTextField.getText();
		Integer value;
		try {
			updatingSize = true;
			value = Integer.decode(valueStr);
			int structureSize = value.intValue();
			if (structureSize < 0) {
				model.setStatus("Structure size cannot be negative.", true);
			}
			else {
				if (structureSize < model.getLength()) {
					// Decreasing structure length.
					// Verify that user really wants this.
					String question =
						"The size field was changed to " + structureSize + " bytes.\n" +
							"Do you really want to truncate " + model.getCompositeName() + "?";
					String title = "Truncate " + model.getTypeName() + " In Editor?";
					int response =
						OptionDialog.showYesNoDialogWithNoAsDefaultButton(this, title, question);
					if (response != OptionDialog.YES_OPTION) {
						compositeInfoChanged();
						return;
					}
				}
				((StructureEditorModel) model).setStructureSize(structureSize);
			}
		}
		catch (NumberFormatException e1) {
			model.setStatus("Invalid structure size \"" + valueStr + "\".", true);
		}
		finally {
			updatingSize = false;
		}
		compositeInfoChanged();
	}
 
Example 10
Source File: CompositeEditorPanel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public void domainObjectRestored(DataTypeManagerDomainObject domainObject) {
	boolean reload = true;
	String objectType = "domain object";
	if (domainObject instanceof Program) {
		objectType = "program";
	}
	else if (domainObject instanceof DataTypeArchive) {
		objectType = "data type archive";
	}
	DataType dt = model.getOriginalDataTypeManager().getDataType(model.getCompositeID());
	if (dt instanceof Composite) {
		Composite composite = (Composite) dt;
		String origDtPath = composite.getPathName();
		if (!origDtPath.equals(model.getOriginalDataTypePath())) {
			model.fixupOriginalPath(composite);
		}
	}
	Composite originalDt = model.getOriginalComposite();
	if (originalDt == null) {
		provider.show();
		String info =
			"The " + objectType + " \"" + domainObject.getName() + "\" has been restored.\n" +
				"\"" + model.getCompositeName() + "\" may no longer exist outside the editor.";
		Msg.showWarn(this, this, "Program Restored", info);
		return;
	}
	else if (originalDt.isDeleted()) {
		cancelCellEditing(); // Make sure a field isn't being edited.
		provider.dispose(); // Close the editor.
		return;
	}
	else if (model.hasChanges()) {
		provider.show();
		// The user has modified the structure so prompt for whether or
		// not to reload the structure.
		String question =
			"The " + objectType + " \"" + domainObject.getName() + "\" has been restored.\n" +
				"\"" + model.getCompositeName() + "\" may have changed outside the editor.\n" +
				"Discard edits & reload the " + model.getTypeName() + "?";
		String title = "Reload " + model.getTypeName() + " Editor?";
		int response = OptionDialog.showYesNoDialogWithNoAsDefaultButton(this, title, question);
		if (response != 1) {
			reload = false;
		}
	}
	if (reload) {
		cancelCellEditing(); // Make sure a field isn't being edited.
		model.load(originalDt, model.isOffline()); // reload the structure
		model.updateAndCheckChangeState();
	}
}
 
Example 11
Source File: RemoveUserCheckoutsScript.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected void run() throws Exception {
	
	Project project = state.getProject();
	
	ProjectData projectData = project.getProjectData();
	
	RepositoryAdapter repository = projectData.getRepository();
	if (repository == null) {
		printerr("Project is not a shared project");
		return;
	}
	
	User currentUser = repository.getUser();
	if (!currentUser.isAdmin()) {
		printerr("You are not a repository administrator for " + repository.getName());
		return;
	}
	
	String uname = askString("Remove User Checkouts" , "Enter user ID to be cleared");
	
	boolean found = false;
	for (User u : repository.getUserList()) {
		if (uname.equals(u.getName())) {
			found = true;
			break;
		}
	}
	if (!found) {
		if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "User Name Confirmation",
				"User '" + uname + "' not a registered server user.\nDo you still want to search for and remove checkouts for this user?") != OptionDialog.YES_OPTION) {
			return;
		}
	}
	
	if (projectData.getFileCount() > 1000) {
		if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "Large Repository Confirmation",
				"Repository contains a large number of failes and could be slow to search.\nDo you still want to search for and remove checkouts?") != OptionDialog.YES_OPTION) {
			return;
		}
	}
	
	int count = removeCheckouts(repository, "/", uname, monitor);
	popup("Removed " + count + " checkouts");
	
}